Angular RXJS-Filter显示为筛选,但结果仍然显示未筛选
我使用的是RXJS 6.3.3 我有以下代码可以过滤掉已经选择的小控件 因此,如果我有:Angular RXJS-Filter显示为筛选,但结果仍然显示未筛选,angular,rxjs,angular-material,Angular,Rxjs,Angular Material,我使用的是RXJS 6.3.3 我有以下代码可以过滤掉已经选择的小控件 因此,如果我有: Gizmos = "Red", "Blue", "Green" 用户选择“蓝色” 我应该只看到“红色”和“绿色”作为可用选项 然而,我仍然看到“红”、“蓝”、“绿” 在“调试”中,过滤器似乎正在运行,它将打印以下示例: Red:true Blue:false Green:true 我不确定我遗漏了什么,因为UI仍然显示所有3个值 <mat-autocomplete #auto="mat
Gizmos = "Red", "Blue", "Green"
用户选择“蓝色”
我应该只看到“红色”和“绿色”作为可用选项
然而,我仍然看到“红”、“蓝”、“绿”
在“调试”中,过滤器似乎正在运行,它将打印以下示例:
Red:true Blue:false Green:true
我不确定我遗漏了什么,因为UI仍然显示所有3个值
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let gizmp of filterGizmos | async" [value]="gizmo.value" (onSelectionChange)="gizmoSelectionChange(gizmo)">
{{gizmo.value}}
</mat-option>
</mat-autocomplete>
filterGizmos: Observable<Gizmo[]>;
this.filterGizmos = this.filterGizmoData(this.searchTerm.value);
filterGizmoData(searchString?: string): Observable<Gizmo[]> {
let tfp = new GizmoFindParameters();
if (searchString == undefined) {
tfp.value = "";
} else {
tfp.value = searchString.trim();
}
return this.gizmoService.find<Gizmo[]>(tfp)
.pipe(tap(x =>
x.filter((y) => {
console.log(y.value);
console.log(!this.selectedGizmos.includes(y.value));
return !this.selectedGizmos.includes(y.value);
})
)
);
};
{{gizmo.value}
filterGizmos:可观察的;
this.filterGizmos=this.filterGizmoData(this.searchTerm.value);
filterGizmoData(searchString?:string):可观察{
设tfp=new GizmoFindParameters();
if(searchString==未定义){
tfp.value=“”;
}否则{
tfp.value=searchString.trim();
}
返回此.gizmoService.find(tfp)
.管道(水龙头(x=>
x、 过滤器((y)=>{
控制台日志(y值);
console.log(!this.selectedGizmos.includes(y.value));
return!this.selectedGizmos.includes(y.value);
})
)
);
};
点击
不会修改流。它通常用于调试和副作用(不影响流的操作)
改用map
这来自点击的文档:
对可观察到的源上的每个发射执行副作用,但是
返回与源相同的可观测值
谢谢你。我没听懂