我是用复选框得到下面的数据列表。
data:[{ email: "email1" }, { email: "email2" }, { email: "email3" }, { email: 'email4' }]
html
<table>
<thead>
<th></th>
<th></th>
</thead>
<tbody>
<td *ngFor="let x of collection;">
<input type="checkbox" (change)="checkEmails($event,x)" />
</td>
<td>{{x.email}}</td>
</tbody>
<table>
.ts文件
public groupList: any = [];
checkEmails(event, email) {
if (event.target.checked) {
if (this.groupList.length == 0) {
this.groupList.push(email);
}
else {
this.groupList.push(email);
}
console.log("bulkData", this.groupList);
}
}
现在列表添加到一个数组中,但当取消选择复选框时,我想从数组中删除列表。
但是当取消选择复选框时,我想把列表从数组中删除,有人能帮帮我吗?
使用 拼接 功能
checkEmails(event, email) {
if (event.target.checked) {
this.groupList.push(email);
console.log("bulkData", this.groupList);
} else {
for(var i = 0 ; i < this.groupList.length; i++) {
if(this.groupList[i].email == email.email) {
this.groupList.splice(i, 1);
}
}
console.log("bulkData1", this.groupList);
}
}