export const flatArray = (treeList, children = "children") => {
let arr = [];
const flat = (list, leaf) => {
if (Array.isArray(list) && list.length) {
list.forEach((item, index) => {
let obj = cloneDeep(item);
delete obj[children];
arr.push(obj);
if (item[children] && item[children].length) {
flat(item[children]);
}
});
}
};
flat(treeList);
return arr;
};
偏平化树状结构数组
![](https://img-home.csdnimg.cn/images/20240711042549.png)