【解决问题】解决dwz增删改查不局部刷新的办法

更新时间:2020-11-29    来源:搜索技术    手机版     字体:

【www.bbyears.com--搜索技术】

一个小项目,用到了dwz,苦于官方少于维护且需要一部分前端技术一直没有深挖,迫在眉睫,遇到了跟很多人一样的问题,就是增删改查不能局部刷新,苦恼啊。经多多放查找资料和翻阅源码终于皇天不负有心。

项目使用TP3.1.3

需要做一下修改

找到 Thinkphp/lib/core/Action.class.php

查找 ajaxReturn 方法

注释掉

if(func_num_args()>2) {// 兼容3.0之前用法
            $args           =   func_get_args();
            array_shift($args);
            $info           =   array();
            $info["data"]   =   $data;
            $info["info"]   =   array_shift($args);
            $info["status"] =   array_shift($args);
            $data           =   $info;
            $type           =   $args?array_shift($args):"";
}


然后在下方添加

if(method_exists($this,"ajaxAssign")) $this->ajaxAssign($data);//ajax赋值扩展


完整代码如下

/**
     * Ajax方式返回数据到客户端
     * @access protected
     * @param mixed $data 要返回的数据
     * @param String $type AJAX返回数据格式
     * @return void
     */
    protected function ajaxReturn($data,$type="") {
//        if(func_num_args()>2) {// 兼容3.0之前用法
//            $args           =   func_get_args();
//            array_shift($args);
//            $info           =   array();
//            $info["data"]   =   $data;
//            $info["info"]   =   array_shift($args);
//            $info["status"] =   array_shift($args);
//            $data           =   $info;
//            $type           =   $args?array_shift($args):"";
//        }
        if(method_exists($this,"ajaxAssign")) $this->ajaxAssign($data);//ajax赋值扩展
        if(empty($type)) $type  =   C("DEFAULT_AJAX_RETURN");
        switch (strtoupper($type)){
            case "JSON" :
                // 返回JSON数据格式到客户端 包含状态信息
                //header("Content-Type:application/json; charset=utf-8");
                 header("Content-Type:text/html; charset=utf-8"); //zhanghuihua
                exit(json_encode($data));
            case "XML"  :
                // 返回xml格式数据
                header("Content-Type:text/xml; charset=utf-8");
                exit(xml_encode($data));
            case "JSONP":
                // 返回JSON数据格式到客户端 包含状态信息
                header("Content-Type:application/json; charset=utf-8");
                $handler  =   isset($_GET[C("VAR_JSONP_HANDLER")]) ? $_GET[C("VAR_JSONP_HANDLER")] : C("DEFAULT_JSONP_HANDLER");
                exit($handler."(".json_encode($data).");"); 
            case "EVAL" :
                // 返回可执行的js脚本
                header("Content-Type:text/html; charset=utf-8");
                exit($data);           
            default     :
                // 用于扩展其他返回格式数据
                tag("ajax_return",$data);
        }
}

在任意一出添加

protected function ajaxAssign(&$result){
        $result["statusCode"]  =  $result["status"];
        $result["navTabId"]  =  $_REQUEST["navTabId"];
        $result["message"]=$result["info"];
}


退出DWZ,重新登录 再试试吧!

本文来源:http://www.bbyears.com/seo/113441.html

热门标签

更多>>

本类排行