|
|
|
|
@ -167,39 +167,21 @@ export const handleTree = <T>(data: any[], id?: string, parentId?: string, child
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const childrenListMap: any = {};
|
|
|
|
|
const nodeIds: any = {};
|
|
|
|
|
const tree: T[] = [];
|
|
|
|
|
|
|
|
|
|
for (const d of data) {
|
|
|
|
|
const parentId = d[config.parentId];
|
|
|
|
|
if (childrenListMap[parentId] == null) {
|
|
|
|
|
childrenListMap[parentId] = [];
|
|
|
|
|
}
|
|
|
|
|
nodeIds[d[config.id]] = d;
|
|
|
|
|
childrenListMap[parentId].push(d);
|
|
|
|
|
const id = d[config.id];
|
|
|
|
|
childrenListMap[id] = d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const d of data) {
|
|
|
|
|
const parentId = d[config.parentId];
|
|
|
|
|
if (nodeIds[parentId] == null) {
|
|
|
|
|
const parentObj = childrenListMap[parentId]
|
|
|
|
|
if (!parentObj) {
|
|
|
|
|
tree.push(d);
|
|
|
|
|
} else {
|
|
|
|
|
parentObj[config.childrenList].push(d)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const adaptToChildrenList = (o: any) => {
|
|
|
|
|
if (childrenListMap[o[config.id]] !== null) {
|
|
|
|
|
o[config.childrenList] = childrenListMap[o[config.id]];
|
|
|
|
|
}
|
|
|
|
|
if (o[config.childrenList]) {
|
|
|
|
|
for (const c of o[config.childrenList]) {
|
|
|
|
|
adaptToChildrenList(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (const t of tree) {
|
|
|
|
|
adaptToChildrenList(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tree;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|