当前位置:网站首页>JS how to realize array to tree

JS how to realize array to tree

2022-07-04 23:53:00 Yisu cloud

js How to realize array to tree

This article introduces “js How to realize array to tree ” Knowledge about , During the operation of the actual case , Many people will encounter such difficulties , Next, let Xiaobian lead you to learn how to deal with these situations ! I hope you will read carefully , Be able to learn !

Native Encapsulating utility functions getTree

1.1 Definition

- Mapping objects map

Array treeList=[]

1.2 Traverse the array returned by the back end list by Each array object item add to children attribute The value is an empty array

js How to realize array to tree

1.3 Is a mapping object map Add attribute And the assignment key:id value value:item

js How to realize array to tree

1.4 Traversing array objects list When item.pid It's empty time It is a primary directory The primary directory array object Add to treeList in

js How to realize array to tree

1.5 adopt item.pid Get id Isn't empty Get array object pid by 01

js How to realize array to tree

1.6 obtain Mapping objects map Get Property name 01 Put the array object item add to To children in And back to treeList in

Code :

js How to realize array to tree

chart :

js How to realize array to tree

“js How to realize array to tree ” That's all for , Thanks for reading . If you want to know more about the industry, you can pay attention to Yisu cloud website , Xiaobian will output more high-quality practical articles for you !

原网站

版权声明
本文为[Yisu cloud]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207042349255767.html