当前位置:网站首页>树形结构数据的处理
树形结构数据的处理
2022-07-03 01:22:00 【13少啊】
在我们做开发的时候,有时候会让我们处理树形结构的数据。今天浅谈一下面对树形的数据该做如何处理。
一.两种结构
(1) 后端返回返回的是树形结构,这个可以跟后端进行商量。
(2)后端返回的是一个平铺的结构,需要通过递归进行转换处理。
二.通过了element-ui来看树形结构。
代码:
<template>
<div class="">
<el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
</div>
</template>
<script>
export default {
data() {
return {
data: [{
label: '一级 1',
children: [{
label: '二级 1-1',
children: [{
label: '三级 1-1-1'
}]
}]
}, {
label: '一级 2',
children: [{
label: '二级 2-1',
children: [{
label: '三级 2-1-1'
}]
}, {
label: '二级 2-2',
children: [{
label: '三级 2-2-1'
}]
}]
}, {
label: '一级 3',
children: [{
label: '二级 3-1',
children: [{
label: '三级 3-1-1'
}]
}, {
label: '二级 3-2',
children: [{
label: '三级 3-2-1'
}]
}]
}],
defaultProps: {
children: 'children',
label: 'label'
}
};
},
methods: {
handleNodeClick(data) {
console.log(data);
}
}
};
</script>
<style scoped></style>
视图:
结构的分析:
分析这种结构:
一级:什么都没有,只有一个label '一级 1'
二级:在children里面继续写label
三级:在二级的后面更着children。
四级:......
三.实际开发
对应接口的文档在做新增的时候,传入上一层的id,即可实现新增。
同理删除也是一样的道理。
边栏推荐
猜你喜欢
Summary of interval knowledge
Why can't the start method be called repeatedly? But the run method can?
Pytest learning notes (12) -allure feature · @allure Step () and allure attach
[技术发展-23]:DSP在未来融合网络中的应用
【数据挖掘】任务5:K-means/DBSCAN聚类:双层正方形
Virtual list
How is the mask effect achieved in the LPL ban/pick selection stage?
STM32 - switch of relay control lamp
Using tensorboard to visualize the model, data and training process
Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day
随机推荐
NCTF 2018 part Title WP (1)
网络安全-NAT网络地址转换
The thread reuse problem of PageHelper using ThreadLocal, did you use it correctly?
C language course information management system
C#应用程序界面开发基础——窗体控制(3)——文件类控件
Why can't the start method be called repeatedly? But the run method can?
GDB 在嵌入式中的相关概念
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance o
View of MySQL
Openresty cache
mysql
Scheme and practice of cold and hot separation of massive data
Function definition and call, this, strict mode, higher-order function, closure, recursion
Take you ten days to easily complete the go micro service series (II)
7-25 read numbers (loop switch)
Main features of transport layer TCP and TCP connection
[interview question] 1369 when can't I use arrow function?
Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day
2022 financial product revenue ranking
[data mining] task 6: DBSCAN clustering