无论我点击哪一行,我都必须在控制台中获取该项。
HTML格式:
<a id="lnk_Condition" (click)="deleteConditionDetails()" style="padding-left: 15px">Delete </a> <p-table #dt [columns]="tableHeaders" [value]="ccdList" [lazy]="true" [paginator]="true" (onLazyLoad)="loadLazy($event)" [totalRecords]="totalcount" [rows]="10"> <ng-template pTemplate="header" let-columns> <tr role="row"> <th width="30"> <input type="checkbox" [(ngModel)]="selectedAll" (change)="selectAll()" #ccdListViewChild> </th> <th width="90">Date Added </th> <th width="300">Description </th> </tr> </ng-template> <ng-template pTemplate="body" let-rowData let-columns="columns"> <tr [pSelectableRow]="rowData"> <td><input type="checkbox" [(ngModel)]="rowData.selected" (change)="checkIfAllSelected();"></td> <td>{{rowData.DateAdded}}</td> <td>{{rowData.Description}}</td> </tr> </ng-template> </p-table>
TS码:
selectAll() { for (var i = 0; i < this.ccdList.length; i++) { this.ccdList[i].selected = this.selectedAll; } } checkIfAllSelected() { this.selectedAll = this.ccdList.every(function (item: any) { return item.selected == true; }) } deleteConditionDetails() { }
Delete 到 button 只是为了方便起见:
Delete
button
<button (click)="deleteConditionDetails()"> Delete </button>
然后在函数中实现:
deleteConditionDetails() { let i=0; for(i=0;i<this.ccdList.length;i++) { if(this.ccdList[i].selected) console.log(this.ccdList[i]); } }