angular - 带有复选框的 Angular Material mat-tree 全选
问题描述
我正在使用带有复选框的 Tree,并且我想添加一个按钮来检查所有复选框,我尝试了不同的方法但效果不佳,我能做到的最好的事情是:
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])
}
}
堆栈闪电战
https://stackblitz.com/edit/angular-hpsj5x?embed=1&file=app/tree-checklist-example.html
推荐阅读
- unix - 如何在 unix 上不输入数百万次密码?
- html - MDBootstrap Angular Material Animation 不适用于输入字段
- php - Wordpress & MDPF 包含外部 php 文件模板
- c++ - 是否可以通过使用其他变量来为变量分配值而不更改它们在 C++ 中的值。?
- c# - 无法在 C# 中终止进程?
- javascript - 从具有正确后备路由结构的nodejs中的异步调用传递数据的最佳实践
- c++ - 为什么我的双向链表删除功能会删除多个节点?
- mongodb - MongoDB聚合:查找数组子对象
- excel - 如何使存储在字典键过滤器中的数据不区分大小写
- talend - Talend 将输入文本转置为 excel