reactjs - 等待多个可观察的 ajax 调用完成
问题描述
在 React Native 项目中使用 redux-observables,我正在尝试进行 ajax 调用来检索消息数组。一旦这个调用完成,我想对数组中的每个项目进行单独的 Ajax 调用,等待它们全部完成,然后使用 redux 操作发布它们。
我曾尝试使用 forkjoin,但我正在努力将数组转换为 observables 数组(我认为这是必要的步骤?)并创建单独的 Ajax 调用,然后等待它们完成。这甚至可能吗?
export const messagesEpic: Epic = (action$, state$) =>
action$.pipe(
ofType('MESSAGES_FETCH'),
mergeMap((_: Action) =>
constructAPICall(
state$,
'GET',
api.endpoints.messages('type', 0),
).pipe(
map(response => < insert transform array to observables and ajax -> wait for all to finish >,
catchError(error => of({
type: GENERAL_API_ERROR,
payload: error.xhr.response,
error: true,
}))
)))
);
在第一次 ajax 调用中收到的数组是一个简单的 json 数组,其中包含包含 id 和其他信息的普通对象。
解决方案
推荐阅读
- amazon-web-services - 通过 Lambda@Edge 来自 KMS 加密存储桶的 AWS CloudFront 自定义 s3 来源
- c# - 无法复制文件“obj \ Debug \ {ProjectName} .exe” - 找不到文件
- python - 在 pytransitions 中处理多个对象
- c# - 尝试将数据从 db 返回到控制器并出现“如果您使用 DataContractSerializer,请考虑使用 DataContractResolver”错误
- python - 如何在python中对数据进行会话化
- discord.py - 我被困在这个带有黑名单角色的反广告链接中
- javascript - 每个 selectedTest 都存在于 data-Test 数组中并获取结果
- r - 在R中的数据框中删除第n行和从n到n + x的行
- javascript - 我的 JavaScript 幻灯片在选择上一个图像后前进图像然后返回
- python - 基于偏移的分页与前向分页 - 如何使用 GraphQL 进行查询