gpt4 book ai didi

javascript - 使用 ngx-filter-pipe angular 过滤多个值

转载 作者:数据小太阳 更新时间:2023-10-29 03:54:47 25 4
gpt4 key购买 nike

我正在使用 Angular 为 4 的 ngx-filter-pipe,但我遇到了这个问题。我设法用一个值过滤,现在我试图用多个值过滤数据:这是我得到的这是我的组件:

@Component({
selector: 'deudas-list',
templateUrl: '../views/deudas-list.html',
providers: [ DeudaService ]
})
export class DeudasListComponent{
public titulo: string;
public deudas: Deuda[];
public userFilter: any = { mes: '' };

constructor(
private _route: ActivatedRoute,
private _router: Router,
private _productoService: DeudaService
) {
this.titulo = 'Listado de Pagos:';
}

ngOnInit() {
this._productoService.getDeudas().subscribe(
result =>{
console.log(result['Cuotas'].Cuota);
this.deudas = result['Cuotas'].Cuota;
},
error => {
console.log(<any>error);
}
);
}
}

这是我的观点

<div class="form-group has-feedback">
<label for="term" class="sr-only">Search</label>
<input type="text" name="term" [(ngModel)]="userFilter.mes" class="form-control" id="term" placeholder="Buscar por mes...">
<span class="glyphicon glyphicon-search form-control-feedback"></span>
</div>
<div *ngIf="deudas" class="table-responsive col-lg-12 tablilla">
<table class="table table-bordered table-striped table-responsive">
<tbody>
<tr *ngFor="let deuda of deudas | filterBy: userFilter | paginate: {itemsPerPage:10,currentPage: p}">
<td>{{deuda.nombre_edificio}}</td>
<td>{{deuda.numero_dpto}}</td>
<td>{{deuda.Annio}}</td>
<td>{{deuda.mes}}</td>
<td>{{deuda.nombre_tipo_cuota}}</td>
<td>{{deuda.monto_cuota}}</td>
<td>{{deuda.nombre_estado_cuota}}</td>
<td>{{deuda.fecha_pago}}</td>
</tr>
</tbody>
</table>
<pagination-controls (pageChange)="p = $event" class="paginador"></pagination-controls>
</div>

我尝试了很多东西,但我无法让它工作这是我正在关注的文档 https://github.com/VadimDez/ngx-filter-pipe我无法让 $or 过滤器如图所示工作 enter image description here

这是我从 ws 得到的数据

enter image description here

如你所见,我正在使用 mes 进行过滤,但我想使用多个 <input type="text" name="term" [(ngModel)]="userFilter.mes" class="form-control" id="term" placeholder="Buscar por mes...">

如有任何帮助,我们将不胜感激。

最佳答案

如果你使用相同的数据类型来过滤一个值,你可以在同一个过滤器中进行,但如果你想要不同的结果,你可以使用 if else 条件或 switch 条件来获得不同的结果作为你的要求

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'CurrencyFilter',
pure: false
})
export class CurrencyFilterPipe implements PipeTransform {
transform(items: number): any {
var OrigionalValue = items;
var franctionCount = parseInt(abp.session.crNoOfDgtsAftrDecimal);
var value = items.toFixed(franctionCount);
var commaSaperatedVal = value.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + abp.session.crDgtGrpSymbol + "");
var selectedSymbol = abp.session.crCurrencySymbol;
var selectedSymbol = "";
var PosCurrFormat = abp.session.crPositivCurrencyFrmt;
var NgtvCurrFormat = abp.session.crNagativeCurrencyFrmt;
var FinalValue;
if (items > 0)
{
switch (PosCurrFormat) {
case "$1.1":
FinalValue = selectedSymbol + commaSaperatedVal;
break;
case "1.1$":
FinalValue = commaSaperatedVal + selectedSymbol ;
break;
case "$ 1.1":
FinalValue = selectedSymbol+" "+ commaSaperatedVal;
break;
case "1.1 $":
FinalValue = commaSaperatedVal + " " + selectedSymbol;
break;
}
return FinalValue
}
if (items < 0) {
commaSaperatedVal = commaSaperatedVal.replace('-','')
switch (NgtvCurrFormat) {
case "($1.1)": FinalValue = "("+selectedSymbol + commaSaperatedVal+")"; break;
case "-$1.1": FinalValue = "-"+selectedSymbol + commaSaperatedVal; break;
case "$-1.1": FinalValue = selectedSymbol + "-"+ commaSaperatedVal; break;
case "$1.1-": FinalValue = selectedSymbol + commaSaperatedVal + "-" ; break;
case "(1.1$)": FinalValue = "(" + commaSaperatedVal + selectedSymbol + ")"; break;
case "-1.1$": FinalValue = "-" + commaSaperatedVal + selectedSymbol; break;
case "1.1-$": FinalValue = commaSaperatedVal + "-"+ selectedSymbol ; break;
case "1.1$-": FinalValue = commaSaperatedVal+selectedSymbol + "-"; break;
case "-1.1 $": FinalValue = "-" + commaSaperatedVal +" "+ selectedSymbol ; break;
case "-$ 1.1": FinalValue = "-" + " "+ selectedSymbol + commaSaperatedVal; break;
case "1.1 $-": FinalValue = commaSaperatedVal + " " + selectedSymbol + "-"; break;
case "$ 1.1-": FinalValue = selectedSymbol + " " + commaSaperatedVal + "-"; break;
case "$ -1.1": FinalValue = selectedSymbol + " " + "-" + commaSaperatedVal; break;
case "1.1- $": FinalValue = commaSaperatedVal + "-" + " " + selectedSymbol; break;
case "($ 1.1)": FinalValue = "(" + selectedSymbol + " " + commaSaperatedVal + ")"; break;
case "(1.1 $)": FinalValue = "(" + commaSaperatedVal +" "+ selectedSymbol + ")"; break;
}
return FinalValue
}
return FinalValue;
}
}

关于javascript - 使用 ngx-filter-pipe angular 过滤多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46289426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com