一、问题描述:
使用el-tree来展示机构树,如果使用官方文档内的方法只能找到所有全选,或者所有办选的节点。无法将子节点已经全部被选中的父节点单独取出。
二、处理方案:
<script>
// 取出所需节点
methods:{
getSimpleCheckedNodes(store) {
const checkedNodes = [];
const traverse = function(node) {
const childNodes = node.root ? node.root.childNodes : node.childNodes;
childNodes.forEach(child => {
if (child.checked) {
checkedNodes.push(child.data);
}
if (child.indeterminate) {
traverse(child);
}
});
};
traverse(store)
return checkedNodes;
}
}
。。。。。。。
// 调用
this.getSimpleCheckedNodes(this.$refs.checkTree.store) // checkTree为el-tree 的ref
</script>