typescript - Angular-tree-component 如何通过复选框选择来捕获选中的节点

标签 typescript treeview angular5 angular-components

我正在使用 angular-tree-component 生成带有复选框选项的树。 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
  };

所以我能够选择树节点(包括子节点),但无法找到任何方法来捕获所有选定(选中)的节点并显示在另一个框中。 enter image description here

最佳答案

您可以使用“event.treeModel.selectedLeafNodeIds”获取树中的选定节点,

例子:

<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]);

关于typescript - Angular-tree-component 如何通过复选框选择来捕获选中的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50109258/

相关文章:

c# - wpf手动生成TreeViewItem容器

angular - 无法绑定(bind)到指令 ('appHasAccess' ),因为它不是 'input' 的已知属性

angular - 从数组循环渲染组件

Javascript/Typescript - 从对象中删除

TypeScript - 将类型附加到元组类型的末尾

c# - 将 an 拖放到特定鼠标位置的 TextBox - 显示插入符号或位置指示器

c# - 从 TreeView 检索节点上的绑定(bind)对象

css - <mat-card> 没有凸起 - 没有边框

typescript - 从现有类型添加属性到类型

Angular 2 错误( 'directives' 在类型 'Component' 中不存在)