diff --git a/cloud-common-plugin/src/main/resources/templates/tree/tree-v2.html b/cloud-common-plugin/src/main/resources/templates/tree/tree-v2.html index eb235ae..b7b0f70 100644 --- a/cloud-common-plugin/src/main/resources/templates/tree/tree-v2.html +++ b/cloud-common-plugin/src/main/resources/templates/tree/tree-v2.html @@ -190,17 +190,45 @@ showSelectNodes(); } }, + beforeCheck: function(treeId, treeNode) { + if(!selectTree.check.chkboxType.SB) { + return true; + } + if(isNodeSelect(treeNode[selectTree.primaryKey])) { + return true; + } + // 清空原有选项 + var nodes = zTree.getCheckedNodes(true); + for(var i = 0, item; item = nodes[i++];) { + zTree.checkNode(item, false, true); + removeSelectNodes(item[selectTree.primaryKey]); + } + return true; + }, onCheck: function(event, treeId, treeNode) { if(!isNodeSelect(treeNode[selectTree.primaryKey])) { - if(treeNode[selectTree.primaryKey] == '0') { - zTree.checkNode(treeNode, false, true); - return; - } else { - selectedNodes.push(treeNode); + var nodes = zTree.getCheckedNodes(true); + for(var i = 0, item; item = nodes[i++];) { + if(item[selectTree.primaryKey] == '0') { + zTree.checkNode(item, false, true); + return; + } else { + selectedNodes.push(item); + } } + // if(treeNode[selectTree.primaryKey] == '0') { + // zTree.checkNode(treeNode, false, true); + // return; + // } else { + // selectedNodes.push(treeNode); + // } showSelectNodes(); } else { - removeSelectNodes(treeNode[selectTree.primaryKey]); + var nodes = zTree.getCheckedNodes(false); + for(var i = 0, item; item = nodes[i++];) { + removeSelectNodes(item[selectTree.primaryKey]); + } + // removeSelectNodes(treeNode[selectTree.primaryKey]); } }, onAsyncSuccess: function(event, treeId, treeNode, msg) {