当前位置:网站首页>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如何实现数组转树”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
边栏推荐
- 高配笔记本使用CAD搬砖时卡死解决记录
- 【js】-【动态规划】-笔记
- uniapp 除了数字,其他输入无效
- Pytoch --- use pytoch to realize linknet for semantic segmentation
- If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
- CTF競賽題解之stm32逆向入門
- Galera cluster of MariaDB - dual active and dual active installation settings
- How many triangles are there in the golden K-line diagram?
- 如何将自己的代码作品快速存证,已更好的保护自己劳动成果
- Build your own minecraft server with fast parsing
猜你喜欢
[IELTS reading] Wang Xiwei reading P3 (heading)
如何报考PMP项目管理认证考试?
Qualcomm WLAN framework learning (30) -- components supporting dual sta
The caching feature of docker image and dockerfile
多回路仪表在基站“转改直”方面的应用
45岁教授,她投出2个超级独角兽
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
Pytoch --- use pytoch to realize linknet for semantic segmentation
Data on the number of functional divisions of national wetland parks in Qinghai Province, data on the distribution of wetlands and marshes across the country, and natural reserves in provinces, cities
In June, the list of winners of "Moli original author program" was announced! Invite you to talk about the domestic database
随机推荐
[monitoring] ZABBIX
C language to quickly solve the reverse linked list
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
How to do the project of computer remote company in foreign Internet?
French scholars: the explicability of counter attack under optimal transmission theory
Galera cluster of MariaDB - dual active and dual active installation settings
同事的接口文档我每次看着就头大,毛病多多。。。
企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
Servlet+jdbc+mysql simple web exercise
香港珠宝大亨,22亿“抄底”佐丹奴
【雅思阅读】王希伟阅读P4(matching1)
Ffmpeg quick clip
法国学者:最优传输理论下对抗攻击可解释性探讨
How to save your code works quickly to better protect your labor achievements
Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
Observable time series data downsampling practice in Prometheus
人脸识别5- insight-face-paddle-代码实战笔记
A mining of edu certificate station
蓝天NH55系列笔记本内存读写速度奇慢解决过程记录
[kotlin] the third day