树代码:
注意:
1、需要设置“node-key”,否则无法获取子节点
2、设置ref节点
<el-tree
:data="orgTreeData"
:props="props"
node-key="id"
show-checkbox
check-strictly
:expand-on-click-node="false"
ref="orgTreeRef"
@check="handleCheckChange"
/>
展开节点代码:
注意:
其中“orgTreeRef”为机构树设置的ref
// 展开所有节点
expandTree() {
for (var i = 0; i < this.$refs.orgTreeRef.store._getAllNodes().length; i++) {
this.$refs.orgTreeRef.store._getAllNodes()[i].expanded = true;
}
},
// 折叠所有节点
unExpandTree() {
for (var i = 0; i < this.$refs.orgTreeRef.store._getAllNodes().length; i++) {
this.$refs.orgTreeRef.store._getAllNodes()[i].expanded = false;
}
},