您好,我有一个返回object
的方法,我计划在最后一次成功调用后调用n
次,并combine
到array
中。 / p>
public getActivity({minprice, maxprice, type}: QueryParams) {
const url = `${BASE_URL}?minprice=${minprice}&maxprice=${maxprice}&type=${type}`;
return this.httpClient.get(url);
}
我不太确定如何在rxjs中执行此操作,但我的预期输出将是这样的:
activities = [{
fetchedItemId: 1
},
{
fetchedItemId: 2
},
{
fetchedItemId: 3
}
]
答案 0 :(得分:0)
getActivity() {
from(new Array(5))
.pipe(
mergeMap(() => this.appService.getActivity(this.filter)),
filter((activity: Activity) => !activity.error),
toArray(),
)
.subscribe((activities: Activity[]) => {
this.activities = activities;
});
}
我设法通过结合使用pipe,mergeMap,filter和toArray来解决它