I'm using angular-tree-component to generate a tree with checkbox options. HTML
<tree-root [nodes]="nodes" [options]="options">
</tree-root>
Typescript:
import { ITreeOptions } from 'angular-tree-component';
import { Component } from '@angular/core';
export class myComponent {
nodes = [
{
name: 'root1',
children: [
{ name: 'root1_child1' },
{
name: 'root1_child2', children: [
{ name: 'grand_child1' },
{ name: 'grand_child2' }
]
}
]
},
{
name: 'root2',
children: [
{ name: 'root2_child1' },
{
name: 'root2_child2', children: [
{ name: 'grand_child1' },
{ name: 'grand_child2' }
]
}
]
}
];
options: ITreeOptions = {
useCheckbox: true
};
optionsDisabled: ITreeOptions = {
useCheckbox: true,
useTriState: false
};
So I'm able to select tree nodes (including children) but not able to find any way where I can capture all the selected (checked) nodes and display on another box.
You can use "event.treeModel.selectedLeafNodeIds" to get the selected node in tree,
Example:
<tree-root [nodes]="treeNode" (select)="onSelect($event)"
(deselect)="onDeselect($event)" [options]="options"></tree-root>
this.selectedTreeList = Object.entries(event.treeModel.selectedLeafNodeIds)
.filter(([key, value]) => {
return (value === true);
}).map((node) => node[0]);
With reference to above answer to get objects you can use
Object.entries(this.treeModel.selectedLeafNodeIds)
.filter(([key, value]) => {
return (value === true);
})
.map((id) => {
let node = this.treeModel.getNodeById(id[0]);
return node;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With