<el-tree
ref="allparntId"
empty-text="暂无数据"
:props="organizationProps"
:expand-on-click-node="false"
@node-click="handleLeftclick"
:load="loadNode"
node-key="id"
lazy
>
<span slot-scope="{ node, data }" class="more-right">
<span><i class="el-icon-folder"></i> {{ node.label }}</span>
<span class="text-right">
<el-dropdown trigger="click">
<span>
<i class="el-icon-more"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item
@click.native="addSameNode"
v-show="firstLevel"
>新增同级</el-dropdown-item
>
<el-dropdown-item @click.native="addChildNode"
>新增下级</el-dropdown-item
>
<el-dropdown-item @click.native="editNode"
>编辑</el-dropdown-item
>
<el-dropdown-item @click.native="deleteNode"
>删除</el-dropdown-item
>
<el-dropdown-item>上移</el-dropdown-item>
<el-dropdown-item>下移</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</span>
</span>
</el-tree>
//data部门
rowList: [],
parentList: [],
//最终结果
reqlist: [],
js 部分
getParent(node) {
var that = this;
if (node.parent.data && !Array.isArray(node.parent.data)) {
node.parent.data instanceof Object && that.rowList.push(node.data.id);
that.getParent(node.parent);
} else if (that.rowList.length === 0) {
if (that.parentList.length === 0) {
that.rowList.push(node.data.id);
}
} else {
that.rowList.push(node.data.id);
}
},
handleLeftclick(data, node) {
this.getParent(node);
//同级tree点击时置空,也可以判断
this.reqlist = this.rowList;
this.rowList = [];
console.log(this.reqlist);
}
element获取tree当前节点id和所有父级节点id
于 2021-12-18 16:15:15 首次发布