当前位置:网站首页>如何获取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>
点击第三级打印结果如下:
边栏推荐
- Integer type of C language
- tutle时钟改进版
- LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703
- BUU-Crypto-[GUET-CTF2019]BabyRSA
- Just do it with your hands 7 - * project construction details 2 - hook configuration
- Actual cases and optimization solutions of cloud native architecture
- [QT] timer
- [excel] PivotChart
- What is MQ?
- PostgreSQL has officially surpassed mysql. Is this guy too strong!
猜你喜欢
光模块字母含义及参数简称大全
[paper summary] zero shot semantic segmentation
LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052
Enterprise level log analysis system elk (if things backfire, there must be other arrangements)
Flask
c语言经典指针和数组笔试题解析
2022 t elevator repair operation certificate examination question bank and simulation examination
[QT] timer
2022 a special equipment related management (elevator) examination questions simulation examination platform operation
[Excel] 数据透视图
随机推荐
el-select如何实现懒加载(带搜索功能)
卸载Google Drive 硬盘-必须退出程序才能卸载
ansys命令
BUU-Reverse-easyre
Accidentally deleted the data file of Clickhouse, can it be restored?
tutle时钟改进版
Electronic components mall and data manual download website summary
[paper summary] zero shot semantic segmentation
Notepad++--显示相关的配置
LC weekly 300
Analysis of classical pointer and array written test questions in C language
Online shrimp music will be closed in January next year. Netizens call No
Redis realizes ranking function
flink1.13 sql基础语法(二)join操作
2022年R2移动式压力容器充装复训题库及答案
js获取对象中嵌套的属性值
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
Letter meaning and parameter abbreviation of optical module Daquan
简易零钱通
Write a complete answer applet (including single choice questions, judgment questions and multiple topics) (III) single choice questions, judgment questions, and the first question display