element tree 获取当前节点和其父级节点的数据
需求:树形菜单点击之后需要形成面包屑,所以需要当前节点和其父级节点的数据。记录一下解决方法,如下。
<el-tree style="height:calc(100vh - 180px)" ref="tree" icon-class="el-icon-caret-right" :data="dataTree" :props="{label:'groupName',children:'groups'}" node-key="key" @node-click="TreeCk" > <!-- :expand-on-click-node="false" --> </el-tree>
TreeCk(e){ //树节点点击 let tree:any = this.$refs.tree; this.treeKey = ''; //初始化 this.breadList = []; //初始化 if (!e.groups){ this.getTreeNode(tree.getNode(e.key)); this.treeKey = e.key; this.treeGroupType = e.groupType; this.getData(); } } getTreeNode(node){ //获取当前树节点和其父级节点 if (node) { if (node.label !== undefined) { this.breadList.unshift(node.label); //在数组头部添加元素 this.getTreeNode(node.parent); //递归 } } }
this.breadList。可以得到当前节点和其父级的lable数组集合。
相关推荐
boneix 2020-10-21
seanzed 2020-10-15
ifconfig 2020-10-14
学留痕 2020-09-20
往后余生 2020-09-17
kka 2020-09-14
redis 2020-09-07
lzccheng 2020-09-06
soyo 2020-08-31
stonerkuang 2020-08-18
LxyPython 2020-08-17
raksmart0 2020-08-17
Lzs 2020-08-14
MrHaoNan 2020-07-31
80530895 2020-07-05
lengyu0 2020-06-28
YarnSup 2020-06-28
huanglianhuabj00 2020-06-27