升级到Angular Material-版本12("@Angular/Material":"^12.1.2&"(后。我似乎无法再从MatTreeFlatDataSource访问_flatteDatas属性。这部分代码在升级前使用:
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);
}
});
现在,_flatteData似乎是只读私有的,它不再工作(根据最新的提交: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) => {
~~~~~~~~~~~~~~
我知道这不是访问扁平数据的正确方式。还有其他选择吗?
您可以通过treeControl
:访问节点
this.treeControl.dataNodes.forEach(item => {
来源:https://stackoverflow.com/a/53545700/6025248