使用 MatTreeFlatDataSource 时如何访问 flattenedData

问题描述 投票:0回答:1

升级到 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 链接):

    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) => {
                    ~~~~~~~~~~~~~~

我知道这不是访问展平数据的正确方法。还有其他选择吗?

angular angular-material treeview flatten
1个回答
3
投票

您可以通过

treeControl
访问节点:

  this.treeControl.dataNodes.forEach(item => {

来源:https://stackoverflow.com/a/53545700/6025248

© www.soinside.com 2019 - 2024. All rights reserved.