当前位置:网站首页>将从后台获取到的数据 转换成 树形结构数据
将从后台获取到的数据 转换成 树形结构数据
2022-08-09 14:54:00 【小羊卷】
将从后台获取到的数据 转换成 树形结构数据
描述:获取到的数据中有id 和pid pid的值是父级的id的值,子需要放到父亲的children属性中,可以有无数个子,无数层级
所以用到迭代
export const treeData = (data, pid) => {
let list = []
data.forEach((obj) => {
if (obj.pid === pid) {
let children = treeData(data, obj.id)
if (children.length) {
obj.children = children
}
list.push(obj)
}
})
return list
}边栏推荐
- WebGL:BabylonJS入门——初探:我的世界
- Use tensorboard remotely on the server
- VS2010:出现devenv.sln解决方案保存对话框
- What is an index in MySql?What kinds of indexes are commonly used?When does an index fail?
- 简单记录下offsetof和container_of
- What are the hot topics in quantitative programmatic trading?
- 单向链表几个比较重要的函数(包括插入、删除、反转等)
- What drives the development of quantitative trading interfaces?
- ASP.Net Core实战——初识.NetCore
- The difference between show and exec in Qt dialog
猜你喜欢

注释,标识符,数据类型

MySQL学习笔记

focal loss原理及简单代码实现

6大论坛,30+技术干货议题,2022首届阿里巴巴开源开放周来了!

【C语言初阶】倒置字符串(输入 I like beijing. 输出beijing. like I)

几何光学简介

内存泄露检测工具VLD(Visual Leak Detector)使用说明

多线程学习

What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.

Simple analysis of regularization principle (L1 / L2 regularization)
随机推荐
Suddenly want to analyze the mortgage interest rate and interest calculation
Basic principles and common methods of digital image processing
正则化原理的简单分析(L1/L2正则化)
Qt控件-QTextEdit使用记录
VS2010:出现devenv.sln解决方案保存对话框
怎么才可以知道量化程序化交易是否有效?
通用的双向循环列表的几个比较重要的函数操作
用户如何正确去认识程序化交易?
What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.
常见编译问题
股票程序化交易如何理解自己的交易系统?
[MySql] implement multi-table query - one-to-one, one-to-many
如何灵活运用量化交易接口的优势取长补短?
Talking about Shallow Cloning and Deep Cloning of ArraryList
CV复习:过拟合、欠拟合
是什么推动了量化交易接口的发展?
复数与复数域
九、【Vue-Router】缓存路由组件 keep-alive标签
内存泄露检测工具VLD(Visual Leak Detector)使用说明
运算符学习