var aTree = [
{ "id": "1", "name": "动物", "pid": "0"},
{ "id": "2", "name": "鸟类", "pid": "3"},
{ "id": "3", "name": "无脊椎动物", "pid": "4"},
{ "id": "4", "name": "哺乳动物", "pid": "5"},
{ "id": "5", "name": "哺乳动物", "pid": "6"},
{ "id": "6", "name": "哺乳动物", "pid": "1"}
];
let obj = {}
aTree.forEach(item => {
if (item.pid === '0') {obj = item}
item.childArr = aTree.filter(items => items.pid === item.id)
})
image.png
网友评论