我在一张td
中有一张带复选框的桌子。我必须为表中的每个复选框找到值。我怎样才能实现?
<tr id="trval" *ngFor="let x of csvData">
<td id="td" (click)="click($event)" contenteditable *ngFor="let y of x;let j=index" [class.active]="i == selectedRow">
<i *ngIf="j==0" id="removeicon" class="fa fa-times-circle icon " aria-hidden="true" readonly="true" (click)="deleterow($event)"></i>
<div *ngIf="j==23" contenteditable>
<input type="checkbox" id="dppcheck" (change)="dppflagchecked()">
</div>
<div *ngIf="j!=23">
{{y}}
</div>
</td>
</tr>
要获取复选框的值,您需要在(change)="dppflaggeedChecked('')"
函数中传递一个值,然后在课堂上的dppflageedchecked()
中进行检索。
<tr id="trval" *ngFor="let x of csvData; index as i">
<td id="td" (click)="click($event)" contenteditable *ngFor="let y of x;let j=index" [class.active]="i == selectedRow">
<i *ngIf="j==0" id="removeicon" class="fa fa-times-circle icon " aria-hidden="true" readonly="true" (click)="deleterow($event)"></i>
<div *ngIf="j==23" contenteditable>
<input type="checkbox" [(ngModel)]="chkbx[i]" id="dppcheck" (change)="dppflagchecked()"> <-- here
</div>
<div *ngIf="j!=23"> {{y}} </div>
</td>
</tr>
** i是复选框的索引,chkbx
是一个变量,而且是一个基于索引的复选框值的对象。
所以在组件中,你会得到像
chkbx = {
0: true, or 1
1: false or 0
};
否则,您可以更改密钥名称,如[(ngModel)]="chkbx['checkbox_'+i]"
和组件,您将获得
chkbx = {
checkbox_0: true, or 1
checkbox_1: false or 0
};