【问题标题】:One input splitted into two filters一个输入分成两个过滤器
【发布时间】:2021-09-14 09:13:18
【问题描述】:

目前我正在尝试使用邮政编码或城市过滤位置。

这是我的输入:

<mat-form-field appearance="fill">
                <mat-label> Adresse: </mat-label>
                <input matInput (ngModelChange)="FilterChanged()"  type="text" name="ort"  [(ngModel)]="adressFilter"/>
            </mat-form-field>

这是我的过滤器,只适用于一个输入(这里我列出了它们)

FilterChanged(){
    this.personsFiltered = of(this.persons).pipe(
      map( p => (!this.adressFilter || this.adressFilter.trim() === '') ? p:p.filter((i: any) => i.ort?.toLowerCase().includes(this.adressFilter.toLowerCase()))), //would work if i delete the other one
      map( p => (!this.adressFilter || this.adressFilter.trim() === '') ? p:p.filter((i: any) => i.plz?.toLowerCase().includes(this.adressFilter.toLowerCase()))), //same like above
      map(p => p.slice(0, 30))
    )
  }

我的目标是用户可以在一个输入中输入邮政编码或城市。如果我只使用一个地址过滤器它可以工作,如果我试图通过一个过滤器过滤它不起作用。

【问题讨论】:

  • 您的代码一个接一个地应用过滤器,因此该人应该在您的情况下同时满足这两个条件。将两个条件都放在p.filter(here) 中,并仅过滤掉不符合两个条件的项目
  • 是的,这就是解决方案,你!

标签: angular pipe


【解决方案1】:

让它成为一个条件行不通?类似i.ort?.toLowerCase().includes(this.adressFilter.toLowerCase() || i.plz?.toLowerCase().includes(this.adressFilter.toLowerCase()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-10
    • 2019-01-17
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 2015-02-05
    • 1970-01-01
    • 2018-08-09
    相关资源
    最近更新 更多