From aa1ec2f6b7a71608dafee692c9d5cb079efe4232 Mon Sep 17 00:00:00 2001 From: "ethan.zhao" Date: Thu, 6 Sep 2018 16:39:32 +0800 Subject: [PATCH] fix(module:cascader): search correctly when a root node is a leaf node --- components/cascader/nz-cascader.component.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/cascader/nz-cascader.component.ts b/components/cascader/nz-cascader.component.ts index 8cda1bbebcc..7a7f03764c3 100644 --- a/components/cascader/nz-cascader.component.ts +++ b/components/cascader/nz-cascader.component.ts @@ -1227,12 +1227,13 @@ export class NzCascaderComponent implements OnInit, OnDestroy, ControlValueAcces if (!sNode.isLeaf) { loopParent(sNode, disabled); } - if (sNode.isLeaf || !sNode.children) { + if (isLeafNode(sNode)) { loopChild(sNode, disabled); } }); path.pop(); }; + const isLeafNode = (node: CascaderOption) => node.isLeaf || !node.children || !node.children.length; const loopChild = (node: CascaderOption, forceDisabled = false) => { path.push(node); const cPath = Array.from(path); @@ -1248,7 +1249,7 @@ export class NzCascaderComponent implements OnInit, OnDestroy, ControlValueAcces path.pop(); }; - this.oldColumnsHolder[ 0 ].forEach(node => loopParent(node)); + this.oldColumnsHolder[ 0 ].forEach(node => isLeafNode(node) ? loopChild(node) : loopParent(node)); if (sorter) { results.sort((a, b) => sorter(a.path, b.path, this._inputValue)); }