1 var setting = { 2 check: { 3 enable: true, 4 chkboxType: { "Y": "", "N": "" }, 5 chkDisabledInherit: false, 6 chkStyle : "checkbox" 7 }, 8 data: { 9 simpleData: { 10 enable: true, 11 idKey: "DEPTCD", 12 pIdKey: "PID", 13 rootPId: "" 14 }, 15 key: { name: "DEPTNM" } 16 }, 17 async: { 18 enable: true, 19 url: '../../Handler/Handler_Dept_B.ashx', 20 dataType: "json", 21 type: "post" 22 }, 23 callback: { 24 onAsyncSuccess: zTreeOnAsyncSuccess , 25 onCheck: zTreeOnCheck 26 } 27 } 28 var treeObj; 29 function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) { 30 treeObj = $.fn.zTree.getZTreeObj("treeDemo"); 31 treeObj.expandAll(true); 32 //treeObj.checkAllNodes(true); 33 InitTree();【NOTICE】【A】 34 } 35 function zTreeOnCheck(event, treeId, treeNode) { 36 var temp = ""; 37 var arryNodes = treeObj.getCheckedNodes(true); //treeObj.transformToArray(); 38 for (var v = 0; v < arryNodes.length; v++) { 39 temp += "," + arryNodes[v].DEPTCD; 40 } 41 if (temp == "") 42 temp = "''"; 43 var part1; 44 var part2; 45 var part3; 46 var index1; 47 var index2; 48 index1 = parent.frames["framePersonlist"].location.href.lastIndexOf('CDS') + 4; 49 part1 = parent.frames["framePersonlist"].location.href.substring(0, index1); 50 index2 = parent.frames["framePersonlist"].location.href.indexOf('&',index1+1); 51 part2 = parent.frames["framePersonlist"].location.href.substring(index1+1,index2) 52 part3 = parent.frames["framePersonlist"].location.href.substring(index2); 53 54 55 parent.frames["framePersonlist"].location.href = part1 + $.trim(temp)+part3; 56 }; 57 58 $(document).ready(function() { 59 $.fn.zTree.init($("#treeDemo"), setting); 60 $("form").offset({ top: 0 }); 61 //InitTree();
【NOTICE】【B】
62 63 }); 64 function InitTree() { 65 var treeObj = $.fn.zTree.getZTreeObj("treeDemo"); 66 var ojecds = "<%=OJBCDS %>"; 67 // alert(ojecds); 68 var array = ojecds.split(","); 69 var node = null; 70 for (var i = 0; i < array.length; i++) { 71 node = treeObj.getNodeByParam("DEPTCD", array[i], null); 72 73 treeObj.checkNode(node, true, false); 74 75 } 76 77 }
如上面的代码所示:
将initTree()函数放在A处事可以正常执行,若果放在B处就不能够正常的执行甚至出现异常或者报错;
分析:
可能是数据源采用异步加载的方式,整个执行的先后有影响吧;