树状结构1
const tree1 = [
{
id: 1,
title:1,
children: [
{
id:11,
title:11,
children:[]
},
{
id:12,
children:[
{
id: 121,
children: []
}
]
}
]
}
]
树状结构2
const tree2 = [
{
id: 1,
children: [
{
id: 12,
children: [
{
id: 121,
children: [
{
id: 1211,
children: []
}
]
},
{
id: 122,
children:[]
},
{
id: 123,
children:[]
}
]
},
{
id: 13,
children: []
}
]
}
]
期望:
const newTree = [
{
id: 1,
title: 1,
children: [
{
id:11,
title:11,
children:[]
},
{
id:12,
children:[
{
id: 121,
children: [
{
id: 1211,
children: []
}
]
},
{
id: 122,
children:[]
},
{
id: 123,
children:[]
}
]
},
{
id: 13,
children: []
}
]
}
]
二次更新:
- tree1与tree2有着微妙的区别,其中字段不一定相同,是需要糅合在一起
- id只为了表示同一节点,不代表上下级之间有长度或大小关联