提交 ba0d2598 编写于 作者: D Dmitry Bolotin 提交者: Wei Zhu

Object cloning in flatArray performed only if object has childrenName field. (#7072)

上级 e3b6430a
......@@ -4,11 +4,15 @@ export function flatArray(data: Object[] = [], childrenName = 'children') {
const result: Object[] = [];
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]);
if (item[childrenName]) {
const newItem = { ...item };
delete newItem[childrenName];
result.push(newItem);
if (item[childrenName].length > 0) {
loop(item[childrenName]);
}
} else {
result.push(item);
}
});
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册