From 92ed5ee9c2c9de0896f9341a28326e19c1d7a819 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 22 Jul 2018 11:28:21 +0800 Subject: [PATCH] fix(module: tree): sync checked node status and push to checkedNodeList (#1809) close #1802 --- components/tree/nz-tree-node.component.html | 1 + components/tree/nz-tree-node.component.ts | 17 +++++++++++++++++ components/tree/nz-tree.component.html | 1 + components/tree/nz-tree.spec.ts | 2 ++ 4 files changed, 21 insertions(+) diff --git a/components/tree/nz-tree-node.component.html b/components/tree/nz-tree-node.component.html index ce0722d3a20..cce7e49aef1 100644 --- a/components/tree/nz-tree-node.component.html +++ b/components/tree/nz-tree-node.component.html @@ -71,6 +71,7 @@ [nzDefaultExpandAll]="nzDefaultExpandAll" [nzDefaultExpandedKeys]="nzDefaultExpandedKeys" [nzDefaultSelectedKeys]="nzDefaultSelectedKeys" + [nzDefaultCheckedKeys]="nzDefaultCheckedKeys" [nzTreeTemplate]="nzTreeTemplate" (clickNode)="clickNode.emit($event)" (dblClick)="dblClick.emit($event)" diff --git a/components/tree/nz-tree-node.component.ts b/components/tree/nz-tree-node.component.ts index 08fca4daf8c..f59affec7bb 100644 --- a/components/tree/nz-tree-node.component.ts +++ b/components/tree/nz-tree-node.component.ts @@ -88,6 +88,23 @@ export class NzTreeNodeComponent implements OnInit, AfterViewInit { return this._expandAll; } + @Input() + set nzDefaultCheckedKeys(value: string[]) { + // should set checked node list + this._defaultCheckedKeys = value; + if (value && value.indexOf(this.nzTreeNode.key) > -1) { + if (this.nzCheckStrictly) { + this.nzTreeService.setCheckedNodeListStrict(this.nzTreeNode); + } else { + this.nzTreeService.setCheckedNodeList(this.nzTreeNode); + } + } + } + + get nzDefaultCheckedKeys(): string[] { + return this._defaultCheckedKeys; + } + @Input() set nzDefaultExpandedKeys(value: string[]) { this._defaultExpandedKeys = value; diff --git a/components/tree/nz-tree.component.html b/components/tree/nz-tree.component.html index bccb5f64b1a..95f2d3a429a 100644 --- a/components/tree/nz-tree.component.html +++ b/components/tree/nz-tree.component.html @@ -16,6 +16,7 @@ [nzDefaultExpandAll]="nzDefaultExpandAll" [nzDefaultExpandedKeys]="nzDefaultExpandedKeys" [nzDefaultSelectedKeys]="nzDefaultSelectedKeys" + [nzDefaultCheckedKeys]="nzDefaultCheckedKeys" (clickCheckBox)="nzCheckBoxChange.emit($event)" (clickExpand)="nzExpandChange.emit($event)" (clickNode)="nzClick.emit($event)" diff --git a/components/tree/nz-tree.spec.ts b/components/tree/nz-tree.spec.ts index 4532311ce0a..f9875dfe608 100644 --- a/components/tree/nz-tree.spec.ts +++ b/components/tree/nz-tree.spec.ts @@ -496,6 +496,7 @@ describe('tree component test', () => { [(ngModel)]="nodes" [nzCheckable]="true" [nzCheckStrictly]="true" + [nzDefaultCheckedKeys]="checkedKeys" [nzMultiple]="multiple" [nzShowLine]="showLine" [nzShowExpand]="showExpand" @@ -505,6 +506,7 @@ describe('tree component test', () => { }) class NzDemoStrictTreeComponent { + checkedKeys = [ '100011' ]; nodes = [ new NzTreeNode({ title : 'root1',