代码之家  ›  专栏  ›  技术社区  ›  Bhrungarajni

如何使用angular2为删除操作选择特定行

  •  0
  • Bhrungarajni  · 技术社区  · 7 年前

    无论我点击哪一行,我都必须在控制台中获取该项。

    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() {
    
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   maha    7 年前

    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]);
        }
     }
    
    推荐文章