【问题标题】:How to get multiple checkbox values in a single <td>如何在单个 <td> 中获取多个复选框值
【发布时间】:2019-09-19 09:43:58
【问题描述】:

我在单个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>

【问题讨论】:

标签: angular checkbox html-table


【解决方案1】:

要获取复选框的值,您需要在 (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
};

【讨论】:

    猜你喜欢
    • 2015-05-20
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多