mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-27 02:18:34 +08:00
17 lines
436 B
TypeScript
17 lines
436 B
TypeScript
import assign from 'object-assign';
|
|
export function flatArray(data = [], childrenName = 'children') {
|
|
const result = [];
|
|
const loop = (array) => {
|
|
array.forEach(item => {
|
|
const newItem = assign({}, item);
|
|
delete newItem[childrenName];
|
|
result.push(newItem);
|
|
if (item[childrenName] && item[childrenName].length > 0) {
|
|
loop(item[childrenName]);
|
|
}
|
|
});
|
|
};
|
|
loop(data);
|
|
return result;
|
|
}
|