2

我从这个例子中得到了几乎 1 比 1 的树:https ://stackblitz.com/angular/nnxeaxmrdob?file=src%2Fapp%2Ftree-checklist-example.ts

我需要的是获取所有选定的值和不确定的值。我知道,所有选定的值均在清单选择变量中持有,但是问题是选择了整个子节点时,我有一系列的父母和孩子,但是只选择了一些孩子,那么我没有父母。

所以再一次,我如何获得选择和不确定的值?

4

1 回答 1

4

在示例中,您可以使用

const partial=this.treeControl.dataNodes
    .filter(x=>this.descendantsPartiallySelected(x))

console.log(this.checklistSelection.selected,partial)

在哪里 (*)

   descendantsPartiallySelected(node: TodoItemFlatNode): boolean {
    const descendants = this.treeControl.getDescendants(node);
    const result = descendants.some(child => this.checklistSelection.isSelected(child));
    return result && !this.descendantsAllSelected(node);
  }

(*)您在示例中还没有此功能

于 2019-11-15T18:45:06.450 回答