|
|
@@ -326,6 +326,7 @@ export class Tree {
|
|
|
// 递归删除节点
|
|
|
const deleteNodes = (nodes: TreeNode[]): void => {
|
|
|
// 删除映射、删除数据
|
|
|
+ const toDels: { nodes: TreeNode[]; delNode: TreeNode }[] = [];
|
|
|
nodes.forEach(node => {
|
|
|
allDeletedNodes.push(node);
|
|
|
delete this.IDMap[node.ID];
|
|
|
@@ -336,7 +337,7 @@ export class Tree {
|
|
|
if (nodesInParentMap && nodesInParentMap.length) {
|
|
|
const nIndex = nodesInParentMap.indexOf(node);
|
|
|
if (nIndex >= 0) {
|
|
|
- nodesInParentMap.splice(nIndex, 1);
|
|
|
+ toDels.push({ nodes: nodesInParentMap, delNode: node });
|
|
|
}
|
|
|
}
|
|
|
const index = this.rawData.indexOf(node);
|
|
|
@@ -347,6 +348,13 @@ export class Tree {
|
|
|
deleteNodes(children);
|
|
|
}
|
|
|
});
|
|
|
+ // 删除parentMap的数据
|
|
|
+ toDels.forEach(delItem => {
|
|
|
+ const delIndex = delItem.nodes.indexOf(delItem.delNode);
|
|
|
+ if (delIndex >= 0) {
|
|
|
+ delItem.nodes.splice(delIndex, 1);
|
|
|
+ }
|
|
|
+ });
|
|
|
};
|
|
|
deleteNodes(treeNodes);
|
|
|
// 排序
|
|
|
@@ -598,8 +606,8 @@ export class Tree {
|
|
|
clear(): void {
|
|
|
this.rawData.splice(0, this.rawData.length);
|
|
|
this.data.splice(0, this.data.length);
|
|
|
- this.parentMap = {};
|
|
|
- this.IDMap = {};
|
|
|
- this.ctxMap = {};
|
|
|
+ Object.keys(this.parentMap).forEach(key => delete this.parentMap[key]);
|
|
|
+ Object.keys(this.IDMap).forEach(key => delete this.IDMap[key]);
|
|
|
+ Object.keys(this.ctxMap).forEach(key => delete this.ctxMap[key]);
|
|
|
}
|
|
|
}
|