wujingjing
2025-04-16 9fd9a0ac506b9f9b84d8b06a2c65efc8cf41bfa3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * 扁平化 Children 结构数组,展开 Children 内容
 * @param tableData
 * @returns
 */
const flatten = (tableData, removeChild, children = 'Children') => {
    const flattenedData = [];
 
    for (const item of tableData) {
        flattenedData.push(item);
        if (item[children] && item[children].length !== 0) {
            flattenedData.push(...flatten(item[children]));
        }
        if (removeChild) {
            Reflect.deleteProperty(item, children);
        }
    }
 
    return flattenedData;
};