抄自 http://tieba.baidu.com/p/4394654036
1 $.ajax({ 2 type: "post", 3 url: ‘/role/getAuthsAll.do‘,//获得全部 4 dataType: ‘json ‘, 5 async: false, 6 success: function(treeAll) { 7 $.fn.zTree.init($("#treeDemo"), setting, treeAll); 8 $.fn.zTree.getZTreeObj("treeDemo").expandAll(true); 9 var nodes = $.fn.zTree.getZTreeObj("treeDemo").getNodes; 10 var array = $.fn.zTree.getZTreeObj("treeDemo").transformToArray(nodes); 11 $.ajax({ 12 type: "post", 13 url: ‘/role/getAuthsAll‘,//获得已有权限 14 data: {id:MenuID}, 15 dataType: ‘json ‘, 16 async: false, 17 success: function (hastree) { 18 for (var i in array) { 19 for (var j in hastree) { 20 if (!array[i].isParent) { //是否为父节点 21 if (array[i].MenuID == hastree[j].MenuID) { 22 $.fn.zTree.getZTreeObj("treeDemo").checkNode(array[i],true,true); 23 } 24 25 } 26 } 27 } 28 } 29 }); 30 } 31 }) 32
时间: 2024-09-29 23:15:31