gpt4 book ai didi

angular - 将 firestore 查询与 rxjs 结合(或查询)

转载 作者:行者123 更新时间:2023-12-01 13:13:20 24 4
gpt4 key购买 nike

我正在尝试使用 RxJS 在 Ionic/Angular 项目中组合两个 firestore 查询。我找到了 this blog post从中解释了基本原理,但是,.combineLatest 方法已被弃用,我无法弄清楚如何将两个查询通过管道传输到 map 中。

caOrCoCities$: Observable<City[]>;

...

const californiaRef = this.angularFirestore
.collection("cities", ref => ref.where("state","==","CA"));
const coloradoRef = this.angularFirestore
.collection("cities", ref => ref.where("state","==","CO"));

不确定如何在下面更新...

this.caOrCoCities$ = Observable
.combineLatest(californiaRef.valueChanges(),
coloradoRef.valueChanges())
.switchMap(cities => {
const [californiaCities, coloradoCities] = cities;
const combined = californiaCities.concat(coloradoCities);
return Observable.of(combined);
});

最佳答案

RxJS 6 在语法上有几处变化。您可以如下所示更改代码。

import { combineLatest, of } from 'rxjs';

this.caOrCoCities$ = combineLatest(californiaRef.valueChanges(), coloradoRef.valueChanges())
.pipe(
switchMap(cities => {
const [californiaCities, coloradoCities] = cities;
const combined = californiaCities.concat(coloradoCities);
return of(combined);
})
);

关于angular - 将 firestore 查询与 rxjs 结合(或查询),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58438916/

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