this. r e f s . t r e e . g e t C h e c k e d N o d e s ( ) 可以获取当前树节点选中数据但是选中最底层字节点时只有该子节点数据无法获取父节点,根据当前业务需求既要获取子节点也要获取当前父节点 t h i s . refs.tree.getCheckedNodes()可以获取当前树节点选中数据但是选中最底层字节点时只有该子节点数据无法获取父节点,根据当前业务需求既要获取子节点也要获取当前父节点 this. refs.tree.getCheckedNodes()可以获取当前树节点选中数据但是选中最底层字节点时只有该子节点数据无法获取父节点,根据当前业务需求既要获取子节点也要获取当前父节点this.refs.tree.getHalfCheckedNodes()通过获取当前选中节点父节点数据
let node = this.$refs.tree.getCheckedNodes()
//选中单个子节点时获取父节点数据
let parentnode = this.$refs.tree.getHalfCheckedNodes()
for(let i =0;i<node.length;i++){
let data = {}
this.$set(data,"operatorId",node[i].id);
this.$set(data,"code",node[i].code);
this.$set(data,"name",node[i].label);
this.$set(data,"roleId",this.rowData.id);
this.roleOperator.push(data);
}
for (let parentIndex = 0 ;parentIndex<parentnode.length;parentIndex++) {
let check =false
node.forEach(item=>{
//如果在选中节点存在则忽视该节点
if (item.id === parentnode[parentIndex].id) {
check = true
}
})
if (!check) {
let data = {}
this.$set(data,"operatorId",parentnode[parentIndex].id);
this.$set(data,"code",parentnode[parentIndex].code);
this.$set(data,"name",parentnode[parentIndex].label);
this.$set(data,"roleId",this.rowData.id);
this.roleOperator.push(data);
}
}