升级到 后 Angular Material - 版本 12 (“@angular/material”:“^12.1.2”)。看来我无法访问 _flattenData 属性(property)不再来自 MatTreeFlatDataSource .这部分代码用于在升级前工作:
this.dataSource._flattenedData.value.forEach(item => {
const issueHasThisItem =
this.data.exitingItems.findIndex(
(loopItem: Entity) =>
(item.level === 1 ||
this.data.treeModalType === TreeModalType.SOLUTION) &&
loopItem.id === item.item.id
) !== -1;
if (issueHasThisItem) {
this.checklistSelection.select(item);
}
});
现在,似乎 _flattenData 是只读私有(private)的,它不再起作用(根据最新提交: Angular Material link ): Error: src/app/modules/issues/components/issue-impact/tree-modal/tree-modal.component.ts:151:21 - error TS2341: Property '_flattenedData' is private and only accessible within class 'MatTreeFlatDataSource<T, F, K>'.
151 this.dataSource._flattenedData.value.forEach((item) => {
~~~~~~~~~~~~~~
我知道这不是如何访问展平数据的正确方法。还有其他选择吗?
最佳答案
您可以通过 treeControl
访问节点:
this.treeControl.dataNodes.forEach(item => {
来源:https://stackoverflow.com/a/53545700/6025248
关于angular - 使用 MatTreeFlatDataSource 时如何访问扁平化数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68439044/