参考学习网址:http://www.treejs.cn/v3/main.php#_zTreeInfo
zTree中父节点禁用,子节点可以用
axios.get('/base/unit/unittree') .then((response) => { let { meta, data } = response.data; if (meta.success) { if (data && data.unitList) { // 部门树数据配置
let unitList = data.unitList; self.unitList = data.unitList; let zNodes = unitList; zNodes[0].open = true; // 初始化部门树 $.fn.zTree.init($("#unitTree"), self.unitTreeSetting, zNodes); var treeObj = $.fn.zTree.getZTreeObj("unitTree"); treeObj.expandAll(true); //父节点不能选择 var nodes = treeObj.transformToArray(treeObj.getNodes()); for (var i=0, l=nodes.length; i < l; i++) { if (nodes[i].isParent){ treeObj.setChkDisabled(nodes[i], true); } } self.assignedUnit=[]; } } });