【问题标题】:How to expand all parent node of particular child node using nested tree control of mat tree in angular 8?如何在角度 8 中使用 mat 树的嵌套树控件扩展特定子节点的所有父节点?
【发布时间】:2020-06-18 18:24:54
【问题描述】:

getBookOutlineBar 方法将获取一个节点列表以及大纲侧边栏打开时需要选择的选定节点。我已经实现了扩展方法来扩展所有父节点,但它只扩展一个特定节点,而不是所有父节点。如果打开页面“标题”并且我单击大纲侧边栏,则应展开所有父节点并选择标题。我在角度 8 中使用了 mat 树的嵌套树控件。(此示例在我的代码中使用:https://stackblitz.com/angular/dklgxbrynad?file=src%2Fapp%2Ftree-nested-overview-example.ts)。请提出任何帮助。


getBookOutlineBar() {
        let customURL = '';
        this.bookService.GetBookOutlineBar(this.bookId, location.hash).subscribe(data => {
          this.dataSource.data = data.list;
          if (data.selectedNode != null) {
            this.selectedNode = data.selectedNode;
            this.treeControl.collapseAll();
            this.expand(this.dataSource.data, this.selectedNode.UniqueId);
          }    
        })
      }
    expand(data: BookOutlineBar[], uniqueId: string): any {
        data.forEach(node => {
          if (node.Children && node.Children.find(c => c.UniqueId === uniqueId)) {
            this.treeControl.expand(node);
            this.expand(this.treeControl.dataNodes, node.UniqueId);
          }
          else if (node.Children && node.Children.find(c => c.Children)) {
            this.expand(node.Children, uniqueId);
          }
        });
      }

【问题讨论】:

    标签: angular tree treeview material-ui mat


    【解决方案1】:

    你的代码

     if (node.Children && node.Children.find(c => c.UniqueId === uniqueId)) {
                this.treeControl.expand(node);
                this.expand(this.treeControl.dataNodes, node.UniqueId);
              }
    

    替换为

     if (node.Children && node.Children.find(c => c.UniqueId === uniqueId)) {
                this.treeControl.expand(node);
                this.expand(this.dataSource.data, node.UniqueId);
              }
    

    【讨论】:

      猜你喜欢
      • 2019-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多