const treeData2 = [{
name: '夏1',
id: 'xia1',
departments: [{
name: '夏1-1',
id: 'xia1-1'
}]
}, {
name: '小夏2',
id: 'xia2'
}, {
name: '夏3',
id: 'xia3',
departments: [{
name: '夏3-1',
id: 'xia3-1'
}, {
name: '夏3-2',
id: 'xia夏3-2',
departments: [{
name: 'xia3-2-1',
id: '3-2-1'
}]
}]
}, {
name: '小夏2',
id: 'xia2'
}
];
我需要把这段数据变成下面的数据,嵌套格式是一样的,只是上面把所有的name 改为title,所有的id 改为key,所有的departments 改为children,
上面的不确定嵌套几层, i need transform up to down,i dont know how many department,
const treeData2 = [{
title: '夏1',
key: 'xia1',
children: [{
title: '夏1-1',
key: 'xia1-1'
}]
}, {
title: '小夏2',
key: 'xia2'
}, {
title: '夏3',
key: 'xia3',
children: [{
title: '夏3-1',
key: 'xia3-1'
}, {
title: '夏3-2',
key: 'xia夏3-2',
children: [{
title: 'xia3-2-1',
key: '3-2-1'
}]
}]
}, {
title: '小夏2',
key: 'xia2'
}
];
求大神帮忙 please!