angular - 全选复选框不应选择禁用的复选框记录角度
问题描述
有数据表,如果选中所有复选框,需要选择哪些在启用的复选框记录中并避免禁用记录。我在下面的代码中尝试了这个,我无法限制禁用的记录选择。
checkuncheckall() {
const totalChecked = this.persons.filter(f => f.checked).length;
const target = totalChecked !== this.persons.length;
this.persons.forEach(f => (f.checked = target));
this.cdRef.detectChanges();
}
html代码:
<td><input type="checkbox" [disabled]="person.firstName === 'Superman'" class="checkboxCls" [value]="person.checked" [checked]="person.checked" name="id" (change)="person.checked = !person.checked"></td>
解决方案
checkuncheckall() {
//First filter enabled checkbox
const filteredCheckboxes = this.persons.filter(f => f.firstName !== "Superman");
const totalChecked = filteredCheckboxes.filter(f => f.checked).length;
const target = totalChecked !== filteredCheckboxes.length;
filteredCheckboxesforEach(f => f.checked = target);
this.cdRef.detectChanges();
}
推荐阅读
- aem - 无法在 AEM 6.3 中为登录用户获取唯一会话
- r - 我试图将数据帧添加到另一个带有标题的数据帧中
- reactjs - 组件未在 React.js 中使用 router-link 呈现
- ios - 纹理 ASTextNode 边框和阴影属性不起作用
- java - 当外部测试用例使用 JUnit 5 失败时,不要启动嵌套测试用例
- asp.net - 如何使用 2 个 gridview 单元格值列来构建超链接
- angular - 检查登录用户时未定义共享服务变量
- php - 如何在招摇文件中包含其他应用程序信息?
- .htaccess - htaccess 文件中的 RewriteRule 重定向其他 URL
- .net - Solr 中的用户特定搜索