我正在使用 Tree with checkboxes ,我想添加一个按钮来检查所有复选框,我尝试了不同的方法但没有好处,我能够实现的最好的事情是:
selectAllFiscal() {
this.rootItems.forEach(node => {
this.todoItemSelectionToggle(node);
});
}
rootItems 是一个根节点数组。
我可以看到在迭代时选择了节点
checklistSelection.selected
,但是浏览器中没有选中复选框,任何人都可以指出问题,谢谢。
最佳答案
为您的方法尝试以下方法
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])
}
}
Blitz
https://stackblitz.com/edit/angular-hpsj5x?embed=1&file=app/tree-checklist-example.html
关于带复选框的 Angular Material 垫树全选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53655995/