<Tree :data="data" ref="tree" show-checkbox multiple></Tree>
getCheckedNodes 获取被勾选的节点
getSelectedNodes 获取被选中的节点
getCheckedAndIndeterminateNodes 获取选中及半选节点
console.log(this.$refs.tree.getCheckedAndIndeterminateNodes())
回显更新
let treeArrsy = JSON.parse(e.tree);//返回的数据
let _this = this;
let tree = this.data;//等于之前的tree
//重新全部赋值folse;
tree.forEach(function(it,index){
tree[index].checked = false;
it.children.forEach(function(it1,index1){
tree[index].children[index1].checked=false;
it1.children.forEach(function(it2,index2){
tree[index].children[index1].children[index2].checked=false;
})
})
})
this.data = [];//清空
tree.forEach(function(item,index){
treeArrsy.forEach(function(item1){
if(item.id == item1.id){
tree[index] = item1;
}
})
})
setTimeout(() => {
this.data = tree;//把遍历处理好的重新赋值
_this.$forceUpdate()//强制更新,这个可以不用
}, 10);
|