带复选框的角材质垫树全选

Abd*_*heb 4 checkbox tree angular-material angular

我正在使用带有复选框的 Tree,并且我想添加一个按钮来检查所有复选框,我尝试了不同的方法但没有好处,我能够实现的最好的事情是:

  selectAllFiscal() {
    this.rootItems.forEach(node => {
      this.todoItemSelectionToggle(node);
    });
  }
Run Code Online (Sandbox Code Playgroud)

rootItems 是一个根节点数组。

我可以看到迭代时选择了节点checklistSelection.selected,但是浏览器中没有选择复选框,任何人都可以指出问题,谢谢。

Mar*_*hal 7

为您的方法尝试以下方法

  checkAll(){
    for (let i = 0; i < this.treeControl.dataNodes.length; i++) {
      if(!this.checklistSelection.isSelected(this.treeControl.dataNodes[i]))
        this.checklistSelection.toggle(this.treeControl.dataNodes[i]);
      this.treeControl.expand(this.treeControl.dataNodes[i])
    }
  }
Run Code Online (Sandbox Code Playgroud)

闪电战

https://stackblitz.com/edit/angular-hpsj5x?embed=1&file=app/tree-checklist-example.html