|
@@ -659,4 +659,18 @@ export class Tree<T extends TreeRaw = TreeRaw> {
|
|
|
Object.keys(this.IDMap).forEach(key => delete this.IDMap[key]);
|
|
Object.keys(this.IDMap).forEach(key => delete this.IDMap[key]);
|
|
|
Object.keys(this.ctxMap).forEach(key => delete this.ctxMap[key]);
|
|
Object.keys(this.ctxMap).forEach(key => delete this.ctxMap[key]);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 检测树结构
|
|
|
|
|
+ check(): TreeNode<T>[] {
|
|
|
|
|
+ const errNodes: TreeNode<T>[] = [];
|
|
|
|
|
+ errNodes.push(...this.checkParent());
|
|
|
|
|
+ return errNodes;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查找不到父项的(parentID对应的节点不存在),返回有问题的节点
|
|
|
|
|
+ private checkParent(): TreeNode<T>[] {
|
|
|
|
|
+ return this.rawData.filter(
|
|
|
|
|
+ node => node.parentID !== this.rootID && !this.IDMap[node.parentID]
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|