我有100个记录的分页每页显示10个复选框,我可以在哪里选择所有10条记录或只有一行 . 我想要计算所有选中的复选框 .
我正在使用一个数组,我使用事件绑定来推送行的唯一值,根据是否选中复选框将其指定为true或false . 我当前使用count作为临时变量,并为每个选中或取消选中的复选框使其为1 / -1 . 这个问题是,如果我选择一行然后选中所有记录的复选框,则显示值为11而不是10 .
具有正确记录和长度集的数组,我无法将其绑定到模板 . 它显示0,因为在此组件的init上,值为0.是否有任何方式可以显示正确的数据.I想到了ngmodel,但只读它才适用于form.Is还有其他任何方式 .
组件:array = []
toggleAll(event) {
if (event.target.checked) {
this.service.list.forEach((obj) => { //the service.list gives me 10 records.
this.array[obj.id] = true;
this.count++
});
}
else {
this.service.list.forEach((obj) => {
delete this.array[obj.id];
this.count--
});
}
}
checkone(event) {
if (event.target.checked) {
this.array[event.target.value] = event.target.checked;
this.count++
} else {
delete this.array[event.target.value];
console.log(Object.keys(this.array));
this.count--
}
}