mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 05:28:20 +08:00
16 lines
395 B
JavaScript
16 lines
395 B
JavaScript
|
export function flatArray(data = [], childrenName = 'children') {
|
||
|
const result = [];
|
||
|
const loop = (array) => {
|
||
|
array.forEach(item => {
|
||
|
const newItem = { ...item };
|
||
|
delete newItem[childrenName];
|
||
|
result.push(newItem);
|
||
|
if (item[childrenName] && item[childrenName].length > 0) {
|
||
|
loop(item[childrenName]);
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
loop(data);
|
||
|
return result;
|
||
|
}
|