【发布时间】:2019-03-29 16:20:22
【问题描述】:
我正在使用这个过滤管道:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'search'
})
export class SearchPipe implements PipeTransform {
transform(items: any[], field: string, value: string): any[] {
if (!items) {
return [];
}
if (!field || !value) {
return items;
}
return items.filter(singleItem =>
singleItem[field].toLowerCase().includes(value.toLowerCase())
)}
}
输入:
<input placeholder="Nome do produto" [(ngModel)]="anunciosFiltro.name" type="text" name="filtra" id="filtra">
我有这张表,我应用了这个管道过滤器:
<div *ngFor="let tabelaAnuncioContas of sortedData?.Contas; let a = index" >
<table>
<tr *ngFor="let anuncio of tabelaAnuncioContas.Anuncio.products | search: 'name' : anunciosFiltro.name; let i = index">
<td>
<svg class="componenteTabelaResponsivo" matTooltip="Anúncio ativo" *ngIf="anuncio.status == 'enabled' && anuncio.associations[0].status == 'linked'" style="width:24px;height:24px" viewBox="0 0 24 24">
<path fill="rgb(161,196,66)" d="M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2Z" />
</svg>
</td>
</tr>
</table>
</div>
我的管道过滤器工作正常,但是当我过滤并进行更改我的表 (sortedData) 的数据的 http 申请时,过滤器不会更新数据:
changeDataTable(){
this.sortedData.Contas[this.indexContaAlterada].Anuncio.products[this.indexAnuncioAlterado].status = status;
}
我在模板中的status保持初始值。
【问题讨论】: