Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module: tree): fix nodes list to render correctly #3326

Merged
merged 3 commits into from
Apr 22, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions components/tree/nz-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ export class NzTreeComponent implements OnInit, OnDestroy, ControlValueAccessor,
return this._searchValue;
}

/**
* To render nodes if root is changed
*/
get nzNodes(): NzTreeNode[] {
return this.nzTreeService.rootNodes;
}

// model bind
@Output() readonly nzExpandedKeysChange: EventEmitter<string[]> = new EventEmitter<string[]>();
@Output() readonly nzSelectedKeysChange: EventEmitter<string[]> = new EventEmitter<string[]>();
Expand Down Expand Up @@ -192,7 +199,6 @@ export class NzTreeComponent implements OnInit, OnDestroy, ControlValueAccessor,
_nzMultiple: boolean = false;
nzDefaultSubject = new ReplaySubject<{ type: string; keys: string[] }>(6);
destroy$ = new Subject();
nzNodes: NzTreeNode[] = [];
prefixCls = 'ant-tree';
classMap = {};

Expand All @@ -212,7 +218,7 @@ export class NzTreeComponent implements OnInit, OnDestroy, ControlValueAccessor,
getNode(n);
});
};
this.nzNodes.forEach(n => {
this.nzTreeService.rootNodes.forEach(n => {
simplejason marked this conversation as resolved.
Show resolved Hide resolved
getNode(n);
});
return nodes.find(n => n.key === key) || null;
Expand Down Expand Up @@ -266,19 +272,20 @@ export class NzTreeComponent implements OnInit, OnDestroy, ControlValueAccessor,

// tslint:disable-next-line:no-any
initNzData(value: any[]): void {
let nzNodes: NzTreeNode[] = [];
if (Array.isArray(value)) {
if (!this.nzTreeService.isArrayOfNzTreeNode(value)) {
// has not been new NzTreeNode
this.nzNodes = value.map(item => new NzTreeNode(item, null, this.nzTreeService));
nzNodes = value.map(item => new NzTreeNode(item, null, this.nzTreeService));
} else {
this.nzNodes = value.map((item: NzTreeNode) => {
nzNodes = value.map((item: NzTreeNode) => {
item.service = this.nzTreeService;
return item;
});
}
this.nzTreeService.isCheckStrictly = this.nzCheckStrictly;
this.nzTreeService.isMultiple = this.nzMultiple;
this.nzTreeService.initTree(this.nzNodes);
this.nzTreeService.initTree(nzNodes);
}
}

Expand Down