ant-design/components/table/util.tsx
Benjy Cui 77a45f0b00 deps: upgrade rc-table (#2958)
* feat: remove Table columns paging, close: #2883

* css: add style for table multi-header

* feat: multi-header supports fitler & sorter and so on

* feat: multi-heaader works with Table[scroll.y]

* feat: multi-header should works with Table[scroll.x]

* style: update code style to please lint
2016-09-09 13:55:41 +08:00

27 lines
757 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;
}
export function treeMap(tree: Object[], mapper: Function, childrenName = 'children') {
return tree.map((node, index) => {
const extra = {};
if (node[childrenName]) {
extra[childrenName] = treeMap(node[childrenName], mapper, childrenName);
}
return assign({}, mapper(node, index), extra);
});
}