当前位置:网站首页>js如何实现数组转树
js如何实现数组转树
2022-07-04 23:49:00 【亿速云】
js如何实现数组转树
本篇内容介绍了“js如何实现数组转树”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
原生 封装工具函数 getTree
1.1 定义
-映射对象 map
数组 treeList=[]
1.2 遍历后端返回的数组 list 为 每个数组对象item 添加 children 属性 值为空数组
1.3 为映射对象 map 添加属性 并赋值key:id值 value:item
1.4 遍历数组对象list 当item.pid为空时 为一级目录 将该一级目录数组对象 添加到treeList中
1.5 通过 item.pid获取到 id 不为空时 获取数组对象 pid为01
1.6 获取 映射对象 map 获取到 属性名01 将该数组对象item 添加 到children中 并返回到treeList中
代码:
结构图:
“js如何实现数组转树”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
边栏推荐
- Excel shortcut keys - always add
- PermissionError: [Errno 13] Permission denied: ‘data. csv‘
- A new method for analyzing the trend chart of London Silver
- Selected cutting-edge technical articles of Bi Ren Academy of science and technology
- 如何报考PMP项目管理认证考试?
- The initial trial is the cross device model upgrade version of Ruijie switch (taking rg-s2952g-e as an example)
- Jar batch management gadget
- "Xiaodeng" domain password policy enhancer in operation and maintenance
- Header file duplicate definition problem solving "c1014 error“
- How long does it take to obtain a PMP certificate?
猜你喜欢
OSEK standard ISO_ 17356 summary introduction
Stm32 Reverse Introduction to CTF Competition Interpretation
Observable time series data downsampling practice in Prometheus
如何用快解析自制IoT云平台
Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)
取得PMP证书需要多长时间?
A new method for analyzing the trend chart of London Silver
【雅思阅读】王希伟阅读P4(matching1)
The input of uniapp is invalid except for numbers
C language to quickly solve the reverse linked list
随机推荐
城市轨道交通站应急照明疏散指示系统设计
业务实现-日志写到同一个行数据里面
[kotlin] the third day
高配笔记本使用CAD搬砖时卡死解决记录
[crawler] XPath for data extraction
华泰证券低佣金的开户链接安全吗?
Robot reinforcement learning synergies between pushing and grassing with self supervised DRL (2018)
【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
同事的接口文档我每次看着就头大,毛病多多。。。
Header file duplicate definition problem solving "c1014 error“
C language to quickly solve the reverse linked list
Basic points of the game setup of the points mall
How to use fast parsing to make IOT cloud platform
[IELTS reading] Wang Xiwei reading P4 (matching1)
Stm32 Reverse Introduction to CTF Competition Interpretation
ICML 2022 || 3DLinker: 用于分子链接设计的E(3)等变变分自编码器
Blue sky nh55 series notebook memory reading and writing speed is extremely slow, solution process record
认识ThreadPoolExecutor
Financial markets, asset management and investment funds