ant-design/components/table/util.tsx

17 lines
436 B
TypeScript
Raw Normal View History

2016-06-22 13:18:43 +08:00
import assign from 'object-assign';
export function flatArray(data = [], childrenName = 'children') {
const result = [];
const loop = (array) => {
array.forEach(item => {
2016-06-22 13:18:43 +08:00
const newItem = assign({}, item);
delete newItem[childrenName];
result.push(newItem);
if (item[childrenName] && item[childrenName].length > 0) {
loop(item[childrenName]);
}
});
};
loop(data);
return result;
}