【发布时间】:2018-12-07 09:01:40
【问题描述】:
我正在建立商店行动。 我的商店模型如下所示:
{
entities: {[n:number]: Client},
ids: number[],
}
我从与给定条件对应的后端获取 id。
然后我需要从后端获取那些尚未存储的实体。
但我不知道如何将获取的 id 传递给withLatestFrom 函数?
const params = {
conditions,
fields: ['id']
};
this.apiService.getList(params)
.pipe(
map(resp => {
const ids: number[] = [];
resp.map((item: Client) => {
ids.push(+item.id);
});
return ids;
}),
withLatestFrom(this.checkEntities()), // how to pass ids ?
tap(resp => {
patchState({
entities: resp[1],
ids: resp[0],
loading: false
});
})
);
private checkEntities(ids: number[]) {
const params: ApiWyszukiwarka = {
conditions: {id: ids},
fields: 'all'
};
return this.apiService.getList(params);
}
或者我做错了什么?
【问题讨论】:
-
withLatestFrom 不支持参数,而是您可以使用 switchMap 和 forkJoin 一起使用,如此处所述 - stackoverflow.com/questions/49774676/…