How to access data from 2 different mat-tree in angular?

て烟熏妆下的殇ゞ 提交于 2020-01-06 05:28:08

问题


in my project, I am using 2 different trees from angular material.

I created a demo on stackblitz here : https://stackblitz.com/edit/angular-wvbg5j.

When I try to access their data, I use treeControl.dataNodes but it only gives me the data from the latest generated tree ("groceries2 and reminders2 tree). It displays dataNodes in the console each time I check/uncheck an item.

So I don't know what to do, is there another way to access tree data? or is there a function that stores both trees in memory?


回答1:


Just add the data source as an argument when you handle the checkbox change :

(change)="todoLeafItemSelectionToggle(node, dataSourceX)"

And inside your function just access to the data attribute :

todoLeafItemSelectionToggle(node: TodoItemFlatNode, dataSource : MatTreeFlatDataSource<TodoItemNode, TodoItemFlatNode>): void {
    console.log(dataSource.data) ;
    this.checklistSelection.toggle(node);
    this.checkAllParentsSelection(node);
    this.getParentNode(node)
  }


来源:https://stackoverflow.com/questions/58725906/how-to-access-data-from-2-different-mat-tree-in-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!