angular - 在所有 Ajax 请求完成后更新组件变量
问题描述
我有一个 URL 列表,我正在调用每个 URL 的 Ajax 请求,例如
private getDayData(urls: string[]) {
const sunrise = [];
from(urls).pipe(
concatMap(url => ajax(url)),
map((ajxRes: any) => ({
date: ajxRes.response.location.time[0].date,
sunrise: ajxRes.response.location.time[0].sunrise,
sunset: ajxRes.response.location.time[0].sunset
}))
).subscribe(response => {
sunrise.push(response);
console.log(sunrise);
});
}
在得到所有结果后,我需要返回这个sunrise
数组。subscribe
每次 Ajax 请求完成时的方法。
解决方案
推荐阅读
- node.js - 来自 Amazon Lambda 上 ffmpeg 的 SIGSEGV
- python - 导入其他文件并使用 main 中的函数
- jquery - Javascript 从谷歌获取建筑物的图像
- python - 调用 .to_excel 时“异常未处理:至少一张表必须可见”
- python - 如何规范化数据框的列,忽略其中的 None 值?
- javascript - 滚动事件以移动 div 并没有始终如一地朝着正确的方向前进
- r - 拆分基于行的矩阵
- swift - 如何在 UIPickerView 中引用选定的行?
- file - ANSI 文本提取到其他文件
- r - R - 根据其他列的组元素数量创建一列