当前位置:网站首页>如何获取el-tree中所有节点的父节点
如何获取el-tree中所有节点的父节点
2022-07-04 05:29:00 【_处女座程序员的日常】
<el-tree ref="tree" :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
<script>
import {
throttle } from 'lodash'
export default {
data() {
return {
data: [
{
label: '一级 1',
value: '1',
children: [{
label: '二级 1-1',
value: '1-1',
children: [{
label: '三级 1-1-1',
value: '1-1-1'
}]
}]
}, {
label: '一级 2',
value: '1-2',
children: [{
label: '二级 2-1',
value: '2-1',
children: [{
label: '三级 2-1-1',
value: '2-1-1'
}]
}, {
label: '二级 2-2',
value: '2-2',
children: [{
label: '三级 2-2-1',
value: '2-1-1'
}]
}]
}, {
label: '一级 3',
value: '3',
children: [{
label: '二级 3-1',
value: '3-1',
children: [{
label: '三级 3-1-1',
value: '3-1-1'
}]
}, {
label: '二级 3-2',
value: '3-2',
children: [{
label: '三级 3-2-1',
value: '3-2-1'
}]
}]
}],
defaultProps: {
children: 'children',
label: 'label'
}
}
},
methods: {
handleNodeClick(data, node) {
// console.log("data是多少呢");
// console.log(node);
// let selectedNode = this.$refs.tree.getNode(node);
this.breadList =[]
this.platform(node);
console.log("value是多少呢");
console.log(this.breadList);
},
// 递归函数
platform(node) {
if (!node.parent) {
// 若无父节点,则直接返回
return
}
this.breadList.unshift(node.data.value)// 将value保存起来
//调用递归
this.platform(node.parent)
},
}
</script>
点击第三级打印结果如下:
边栏推荐
- 接地继电器DD-1/60
- Integer type of C language
- 724. Find the central subscript of the array
- Programmers don't talk about morality, and use multithreading for Heisi's girlfriend
- Remote desktop client RDP
- [QT] create mycombobox click event
- (4) Canal multi instance use
- LM small programmable controller software (based on CoDeSys) note XXI: error 3703
- Input displays the currently selected picture
- Notepad++--显示相关的配置
猜你喜欢

检漏继电器JY82-2P

LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052

空洞卷积、可变形卷积、可变形ROI Pooling

Graduation design of small programs -- small programs of food and recipes

Flask

VB. Net GIF (making and disassembling - optimizing code, class library - 5)

19.Frambuffer应用编程

1480. Dynamic sum of one-dimensional array

Simulated small root pile
![BUU-Crypto-[HDCTF2019]basic rsa](/img/d0/8e451dabb2a6897f6680220d16d04d.jpg)
BUU-Crypto-[HDCTF2019]basic rsa
随机推荐
Just do it with your hands 7 - * project construction details 2 - hook configuration
力扣(LeetCode)184. 部门工资最高的员工(2022.07.03)
724. Find the central subscript of the array
【QT】制作MyComboBox点击事件
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
冲击继电器JC-7/11/DC110V
How to use postman to realize simple interface Association [add, delete, modify and query]
Simulated small root pile
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
VB. Net simple processing pictures, black and white (class library - 7)
Build an Internet of things infrared temperature measuring punch in machine with esp32 / rush to work after the Spring Festival? Baa, no matter how hard you work, you must take your temperature first
JS扁平化数形结构的数组
js如何将秒转换成时分秒显示
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
Trie number dictionary tree
Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC
BUU-Real-[PHP]XXE
BUU-Reverse-easyre
2022g2 power station boiler stoker special operation certificate examination question bank and answers
IP时代来临,电竞酒店如何借好游戏的“东风”?