|
|
@@ -61,7 +61,7 @@ export class Tree<T = any> {
|
|
|
// 节点上下文与节点ID映射
|
|
|
ctxMap: CtxIDMap<T>;
|
|
|
|
|
|
- constructor(rawData: TreeRaw[], rootID = '-1') {
|
|
|
+ constructor(rawData: TreeRaw[], rootID = '-1', expanded?: boolean) {
|
|
|
this.rootID = rootID;
|
|
|
this.rawData = this.genNodeContext(rawData);
|
|
|
this.rawData = Tree.sort(this.rawData);
|
|
|
@@ -69,7 +69,7 @@ export class Tree<T = any> {
|
|
|
this.IDMap = {};
|
|
|
this.parentMap = {};
|
|
|
this.ctxMap = {};
|
|
|
- this.genMap(this.rawData);
|
|
|
+ this.genMap(this.rawData, expanded);
|
|
|
this.genData();
|
|
|
}
|
|
|
|
|
|
@@ -94,10 +94,10 @@ export class Tree<T = any> {
|
|
|
}
|
|
|
|
|
|
// 生成映射表
|
|
|
- private genMap(data: (TreeNode & T)[]): void {
|
|
|
+ private genMap(data: (TreeNode & T)[], expanded?: boolean): void {
|
|
|
data.forEach(item => {
|
|
|
this.IDMap[item.ID] = item;
|
|
|
- this.ctxMap[item.ID] = new NodeContext(item, this);
|
|
|
+ this.ctxMap[item.ID] = new NodeContext(item, this, expanded);
|
|
|
(
|
|
|
this.parentMap[item.parentID] || (this.parentMap[item.parentID] = [])
|
|
|
).push(item);
|