如何使用 MatTreeFlatDataSource 访问 flattenedData

How do I access flattenedData whn using MatTreeFlatDataSource

升级到 Angular Material - 版本 12 后(“@angular/material”:“^12.1.2”)。看来我无法再从 MatTreeFlatDataSource 访问 _flattenData 属性。这部分代码在升级前使用:

    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 似乎是只读私有的,它不再起作用(根据最新提交: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 => {

来源: