各位大神,帮忙看一下,小第最近在做zTree树,版本为最新3.5版,刚开始加载有数据,但是异步加载获取到数据后无法跟新ztree树结构, 根据官方api的写法,就是我注释的代码,点击节点时,方法根本进不去ashx方法(一般处理程序)代码如下:
var zNodes; var setting = { async: { autoParam: ["id"], //contentType: "application/json", //dataFilter: ajaxDataFilter, //dataFilter: function (treeId, parentId, childNodes) { // //alert('a'); // return childNodes; //}, dataType: "json", enable: true, otherParam: { "ajaxMethod": "AnsyData"}, type:"post", url: "../ASHX/TestData.ashx", }, callback: { onClick: zTreeOnClick }, data: { key: { name: "F_CHINESE" }, simpleData: { enable: true, idKey: "F_RAD_ID", pIdKey: "F_PARENT_ID", rootId: 0 } } };
1 //鼠标单击节点事件 2 function zTreeOnClick(event,treeId,treeNode,clickFlag) { 3 $.getJSON("../ASHX/TestData.ashx?ajaxMethod=AnsyData&F_RAD_ID="+treeNode.F_RAD_ID, function (zNodes) { 4 alert(zNodes); 5 var treeObj = $.fn.zTree.getZTreeObj("treeDemo"); 6 treeObj.reAsyncChildNodes(zNodes, "refresh"); 7 treeObj.updateNode(zNodes); 8 }); 9 } 10 11 $(document).ready(function () { 12 $.getJSON("../ASHX/TestData.ashx?ajaxMethod=FirstAnsyData", function (zNodes) { 13 $.fn.zTree.init($("#treeDemo"), setting, zNodes); 14 }); 15 16 });
你先看看你../ASHX/TestData.ashx?ajaxMethod=AnsyData&F_RAD_ID="+treeNode.F_RAD_ID有东西吗
数据可以获取到,只是更新不了树结构,问题已经解决了,分都给你了