【问题标题】:remove item from PrimeNG data table从 PrimeNG 数据表中删除项目
【发布时间】:2017-01-03 01:16:05
【问题描述】:

我正在尝试从绑定列表中删除一个项目:

<p-dataTable [value]="items">
   <p-column styleClass="col-button">
      <template let-item="rowData" pTemplate="body">
         <button type="button" pButton (click)="remove(item)" icon="fa-remove"></button>
   </template>
</p-column>
            <p-column *ngFor="let item of settings.columns">
                <template let-row="rowData" let-rowIndex="rowIndex" pTemplate="body">
                    <input [type]="item.type" [(ngModel)]="row[item.field]"  class="form-control" [placeholder]="item.title">
                </template>
            </p-column>
        </p-dataTable>

remove(data){
    this.items.splice(this.items.indexOf(data), 1);
}

该项目已从项目集合中删除,但表格始终删除最后一个。

我做错了什么?

【问题讨论】:

    标签: angular primeng


    【解决方案1】:

    好的,这是 primeNG 1.1.2 的一个错误。 github上有一个解决方案:

    我已经在我的项目中使用自定义 rowTrackBy 修复了它

    rowTrackBy(index: number, row: any) { return row.id; }
    

    只是映射到p-dataTable的对应属性

    [rowTrackBy]="rowTrackBy"
    

    感谢 NikitaForm 。

    https://github.com/primefaces/primeng/issues/1679

    【讨论】:

      猜你喜欢
      • 2018-09-30
      • 2013-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多