如何从2个不同的mat-tree中按角度访问数据? [英] How to access data from 2 different mat-tree in angular?
问题描述
在我的项目中,我正在使用2种不同角度材料的树木.
in my project, I am using 2 different trees from angular material.
我在这里在stackblitz上创建了一个演示: https://stackblitz.com/edit/angular-wvbg5j .
I created a demo on stackblitz here : https://stackblitz.com/edit/angular-wvbg5j.
当我尝试访问他们的数据时,我使用treeControl.dataNodes,但是它只提供最新生成的树("groceries2和hinters2树")中的数据.每次我选中/取消选中一个项目时,它都会在控制台中显示dataNodes.
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?
推荐答案
在处理复选框更改时,只需将数据源添加为参数即可:
Just add the data source as an argument when you handle the checkbox change :
(change)="todoLeafItemSelectionToggle(node, dataSourceX)"
在函数内部,只需访问data属性即可:
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)
}
这篇关于如何从2个不同的mat-tree中按角度访问数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!