一个输入分成两个过滤器
One input splitted into two filters
目前我正在尝试使用邮政编码或城市过滤位置。
这是我的输入:
<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))
)
}
我的目标是用户可以在一次输入中输入邮政编码或城市。如果我只使用一个 adressFilter 它会起作用,如果我试图通过一个过滤器来过滤两者它就不起作用。
把它变成一个条件行不通?类似于 i.ort?.toLowerCase().includes(this.adressFilter.toLowerCase() || i.plz?.toLowerCase().includes(this.adressFilter.toLowerCase()
目前我正在尝试使用邮政编码或城市过滤位置。
这是我的输入:
<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))
)
}
我的目标是用户可以在一次输入中输入邮政编码或城市。如果我只使用一个 adressFilter 它会起作用,如果我试图通过一个过滤器来过滤两者它就不起作用。
把它变成一个条件行不通?类似于 i.ort?.toLowerCase().includes(this.adressFilter.toLowerCase() || i.plz?.toLowerCase().includes(this.adressFilter.toLowerCase()