78373

默认展开ztree树形菜单

var setting = { view: { selectedMulti: false //按住ctrl是否可以多选 }, check: { enable: true , chkStyle: 'checkbox' }, data: { simpleData: { enable: true } }, async: { enable: true ,type:"post" ,url:commandExec.ztreeDftUrl ,dataFilter:function (treeId, parNode, jsonData) { return commandExec.replaceIcon(treeId, jsonData); } }, callback: { //禁止节点被选中 beforeClick:function () { return false; }, onCheck:function (e, treeId, treeNode) { var treeNode = commandExec.onlyCheckedDevice(treeId,treeNode); commandExec.setDeviceBoxValue(treeNode); }, onAsyncSuccess:function (e, treeId, treeNode, nodes) { if(JSON.parse(nodes).length>0){ }else{ layer.alert("暂无数据!"); return; } } } }; /** * 跟换小图标 * */ commandExec.replaceIcon = function(treeId, jsonData){ var treeObj = $.fn.zTree.getZTreeObj(treeId); if(jsonData.length>0){ if(jsonData){ for(var i in jsonData){ var node = jsonData[i]; if(String(node.id).indexOf("tower") >= 0){ node.icon = Electric.ctxPath+"/static/img/icon-tower.png"; //展开 node.open = true; }else if(String(node.id).indexOf("org") >= 0){ node.icon = Electric.ctxPath+"/static/img/icon-company.png"; node.open = true; }else if(String(node.id).indexOf("line") >= 0){ node.icon = Electric.ctxPath+"/static/img/icon-line.png"; node.open = true; }else if(String(node.id).indexOf("device") >= 0){ node.icon = Electric.ctxPath+"/static/img/icon-device.png"; } } } } return jsonData; }; //展开选中节点 var expandCheckedNode = function(){ //获取所有选中状态的节点 var checkedNodes = zTreeObj.getCheckedNodes(true); for(var i in checkedNodes){ var checkedParAll = getParsAll(checkedNodes[i]); for(var j in checkedParAll){ zTreeObj.expandNode(checkedParAll[j],true,false); } } };

来源:博客园

作者:littleboyck

链接:https://www.cnblogs.com/littleboyck/p/11425751.html

Recommend