如何获取 Angular 材质树中所选子节点的值

huangapple go评论62阅读模式
英文:

How to get selected child node values in a angular mat tree

问题

In angular 14 mat tree, have structure like parent --> child --> sub child . If I select child check box then it select all sub child elements. here I want only sub child selected values when I click on submit button.

here is the stack Blitz example I tried.
Stack Blitz 示例链接

here when I click on submit, it's returning all selected dependents. I want only sub child selected check values.

Please help me. Thanks in advance.

英文:

In angular 14 mat tree, have structure like parent --> child --> sub child . If I select child check box then it select all sub child elements. here I want only sub child selected values when I click on submit button.

here is the stack Blitz example I tried.
https://stackblitz.com/edit/nested-multi-select-tree-demo-nymntq?file=app%2Ftree-nested-overview-example.html,app%2Ftree-nested-overview-example.ts

here when I click on submit, it's returning all selected dependents I want only sub child selected check values.

Please help me. Thanks in advance.

答案1

得分: 0

If hierarchy is up to 3 levels and you want to get sub-child only, you can easily achieve it by customizing your filter method in the submit function.

.filter((descendant) => descendant.isSelected && descendant['children'] === undefined)

link

英文:

If hierarchy is upto 3 level & you want to get sub-child only, You Can easily get it with customizing your filter method in submit function.

.filter((descendant) => descendant.isSelected && descendant['children'] === undefined)

link

huangapple
  • 本文由 发表于 2023年4月7日 04:22:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75953470.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定