当前位置:网站首页>js-----数组转换成树形结构
js-----数组转换成树形结构
2022-08-10 08:22:00 【cc&】
/**
* Created by PanJiaChen on 16/11/18.
*/
/**
* 公用方法
* @param {*} list
*/
/**
* 转换树形数据
* @param {*} list 需要转换的部门数据
* @returns
*/
export function listToTreeData(list) {
const treeList = []
const map = {}
list.forEach((item) => {
map[item.id] = item
})
list.forEach((item) => {
if (item.pid === -1) return
const parent = map[item.pid]
if (parent) {
if (!parent.children) {
parent.children = []
}
parent.children.push(item)
} else {
treeList.push(item)
}
})
return treeList
}
边栏推荐
- 上课笔记(7)(1)——#647. 找树根和孩子(root)
- 物联网时代下的网络整合推广外包精准化效果-深圳双赢世讯
- Rust learning: 6.3_ Tuples of composite types
- It is obvious that a unique index is added, why does it still generate duplicate data?
- 如何远程调试对方的H5页面
- Uni-app develops WeChat applet using local images as background images
- 数据库公共字段自动填充
- phpstudy开机自启
- iwemeta元宇宙:一个娃娃卖9999元,泡泡玛特认为一点也不贵
- Rust学习:6.3_复合类型之元组
猜你喜欢
随机推荐
A File Online Query Display and Download Function Realized by Delphi
【Unity入门计划】2D游戏实现敌人来回移动控制脚本
推荐几个高质量的软件测试实战项目
大佬们,请问一下,oraclecdc报错没有序列化,可是我看源码中的确是没有继承序列化的,是什么原因
VMware ESX Server常用命令行
Unity—UGUI控件
PLSQL学习第二天
神经网络样本太少怎么办,神经网络训练样本太少
自动化测试框架搭建 ---- 标记性能较差用例
Uni-app develops WeChat applet using local images as background images
VS2013-debug assembly code-generate asm file-structure memory layout-function parameter stack-calling convention
【Unity入门计划】Collision2D类&Collider2D类
如何设计神经网络结构,神经网络设计与实现
ATH10 sensor reads temperature and humidity
Relaxation class: the boss will martial arts, who also can not hold up against!The charm of six sigma training
Rust学习:6.2_复合类型之元组
张驰课堂:老板会武术,谁也挡不住!六西格玛培训的魅力
[机缘参悟-65]:《兵者,诡道也》-7-三十六计解读-败战计
占位占位1
Rust learning: 6.5_Array of composite types