在Angular6Web应用程序中,我有一个表,其中每行都有一个复选框。
我在考虑向数据模型中添加一个isSelected bool,然后对所有选中的行执行foreach,然后我发现 this post
有没有人能在第六章中提出最好的解决办法?
我还没有开始编写这个代码,因为我不知道链接文章中的方法是否适合angular,或者我是否在浪费时间。
最简单的方法是首先创建一个数组:
checkarray: any[] = [];
每次检查表中的内容时,此数组将被填充或清空:
checkbox(item: any, event) { if (event.ctrlKey) { if (this.checkarray.find(x => x.ID == item.ID)) { this.checkarray.splice(this.checkarray.indexOf(item), 1); } else { this.checkarray.push(item); } } else { this.checkarray.splice(0); this.checkarray.push(item); } }
当您想从数据库中删除项目时,只需将您的数组发送到服务器并执行您的操作。