当前位置:网站首页>如何获取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>
点击第三级打印结果如下:
边栏推荐
- left_ and_ right_ Net normal version
- BUU-Crypto-[GXYCTF2019]CheckIn
- C language simple student management system (including source code)
- 拓扑排序和关键路径的图形化显示
- 检漏继电器JY82-2P
- Analysis of classical pointer and array written test questions in C language
- LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052
- 总线的基本概念
- 2022 R2 mobile pressure vessel filling retraining question bank and answers
- Programmers don't talk about morality, and use multithreading for Heisi's girlfriend
猜你喜欢

Evolution of system architecture: differences and connections between SOA and microservice architecture

Flask

Enterprise level log analysis system elk (if things backfire, there must be other arrangements)

Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology

724. 寻找数组的中心下标

BeanFactoryPostProcessor 与 BeanPostProcessor 相关子类概述

RSA加密应用常见缺陷的原理与实践

云原生架构实战案例及优化解决方案

BUU-Reverse-easyre

ping端口神器psping
随机推荐
简易零钱通
Excel comparator
【雕爷学编程】Arduino动手做(105)---压电陶瓷振动模块
JS string splicing enhancement
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
Simulated small root pile
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
ansys命令
[paper summary] zero shot semantic segmentation
fastjson
Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC
Electronic components mall and data manual download website summary
LM小型可编程控制器软件(基于CoDeSys)笔记二十二:错误4268/4052
如何判断数组中是否含有某个元素
Thinkphp6.0 middleware with limited access frequency think throttle
[excel] PivotChart
(4) Canal multi instance use
Simulink and Arduino serial port communication
Flink1.13 SQL basic syntax (I) DDL, DML
js如何将秒转换成时分秒显示