当前位置:网站首页>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
}边栏推荐
- .NET-7.WPF learning experience summary
- [In-depth study of 4G/5G/6G topic-56]: L3 signaling control-5-radio bearer management
- How AliExpress sellers seize product search weight
- .NET-8. My Thought Notes
- navicat for mysql 连接时报错:1251-Client does not support authentication protocol requested by server
- Introduction to the C language to realize bubble sort
- 模糊查询除了like+ % 还能用什么方式
- 神经网络的三种训练方法,神经网络训练全过程
- Rust学习:6.1_复合类型之切片
- 本地生活商家如何通过短视频赛道,提升销量曝光量?
猜你喜欢

一文2600字手把手教你编写性能测试用例

【Unity入门计划】2D游戏实现敌人来回移动控制脚本

第十六天&charles的基本操作

明明加了唯一索引,为什么还是产生重复数据?

解决win10win7win8系统找不到指定的模块,注册不了大漠插件的问题

物联网时代下的网络整合推广外包精准化效果-深圳双赢世讯

Rust learning: 6.3_ Tuples of composite types

2022-08-01 网工进阶(二十三) VLAN高级技术-VLAN聚合、MUX VLAN

Uni-app develops WeChat applet using local images as background images

自动化测试框架Pytest(一)——入门
随机推荐
Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
iwemeta元宇宙:一个娃娃卖9999元,泡泡玛特认为一点也不贵
自动化测试框架搭建 ---- 标记性能较差用例
第十六天&charles的基本操作
Introduction to the C language to realize bubble sort
LaTeX出现错误代码Command \algorithmic already defined
QT下载清华源配置
Relaxation class: the boss will martial arts, who also can not hold up against!The charm of six sigma training
Rust learning: 6.2_ Tuples of composite types
Rust学习:6.5_复合类型之数组
AFNetworking概述和4.0的实践
[深入研究4G/5G/6G专题-56]: L3信令控制-5-无线承载管理
Day36 LeetCode
PLSQL学习第二天
一文2600字手把手教你编写性能测试用例
The probability distribution and its application
The implementation of the seemingly useless component (text gradient) in NaiveUI is so simple
Class Notes (7) (1) - #647. Find the root and the child (root)
winget package manager
自动化测试框架Pytest(一)——入门