function toTree(list,parId){ let len = list.length function loop(parId){ let res = []; for(let i = 0; i < len; i++){ let item = list[i] if(item.parentId === parId){ item.children = loop(item.id) res.push(item) } } return res } return loop(parId) } let result = toTree(arr,0)
js S数组转成tree
最新推荐文章于 2022-08-11 21:19:23 发布