=========
待补充示例
=========
需求描述:点击任意子节点都能获取到其一级节点属性
解决方法:【selectDept(item, e)】其中,item, e分别为所对应的对象、节点对应的 Node
<el-tree
:data="deptTree"
id="dept-tree"
node-key="id"
default-expanded-all
:props="deptTreeProps"
:expand-on-click-node="true"
@node-click="selectDept"
>
<div class="tree-node-group" slot-scope="{ node, data }">
<span class="tree-node-title">
<span class="node-label">{{ node.label}}</span>
</span>
</div>
</el-tree>
selectDept(item, e) {
console.log(item);
// this.deptInfoForm.parentName = item.name;
this.$set(this.userInfoForm, "departmentName", item.name);
this.$set(this.userInfoForm, "departmentId", item.id);
this.findCompany(e);
},
// 找到公司id----一级节点为公司e,e.parent.data.name == undefined
findCompany(e) {
if (e.parent.data.name == undefined) {
this.$set(this.userInfoForm, "companyId", e.data.id);
} else {
return this.findCompany(e.parent);
}
}