var list = [
{
id: '1',
appName: 'name',
children: [
{
id: '11',
pid: '123',
appId: '123',
children: []
},
{
id: '22',
pid: '456',
appId: '456',
children: []
},
{
id: '33',
pid: '33434',
appId: '456',
children: []
},
]
}
]
function map(list) {
return list.reduce((res, item) => {
if(Array.isArray(item.children) && item.children.length) res.push({...item, children: map(item.children)})
else if(item.pid === item.appId) res.push(item)
return res;
}, []);
}
map(list)
是这样?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…