多个fetch异步调用,不能拿到调用之后的值
export const editCase = () => (dispatch, getState) => {
let caseObject = jquery.extend(true, {}, getState().caseDetail.caseObject)
let platforms = getPlatforms()
let countries = getCountries()
dispatch(initializeCreator(caseObject, platforms, countries, true))
}
执行dispatch函数的时候,此时platforms,countries还没有拿到值
const initializeCreator = (caseObject, platforms, countries, isEdit) => ({
type: types.EDIT_CASE,
caseObject,
platforms,
countries,
isEdit
})
const getPlatforms = () => {
fetch(constants.FETCH_URL + '/platforms', {
mode: 'cors',
method: 'GET',
cache: 'default',
credentials: 'include'
})
.then(response => response.json())
.then(platforms => {
return platforms
})
}
const getCountries = () => {
fetch(constants.FETCH_URL + '/region/countryList', {
mode: 'cors',
method: 'GET',
cache: 'default',
credentials: 'include'
})
.then(response => response.json())
.then(countryNames => {
let countryOptions = []
countryNames.map((countryName, index) => {
countryOptions.push({countryName})
})
return {
countryNames,
countryOptions
}
})
}
相关阅读:
c const 关键字疑问
linux系统下udp包没有收到
请教下 string::data 或 string::c_str的应用方向?
面试经典问题:Cookie禁用了,Session还能用吗?
SUI与swiper能否兼容?
win10 hyper-v 安装Ubuntu黑屏
WSS、SSL 和 https 之间的关系
实在是找不出问题在哪了,麻烦大家找找BUG出在哪
传统diff算法的算法复杂度为什么是o(n3)?
支付宝新版本app支付接口的notify_url在哪里添加?
ubuntu16.04装好后1920*1080显示不全是怎么回事啊?
JDBC访问数据库, set names utf8 无法解决乱码问题.
jq 如何获取多列的高度
c++ 类名后<>里面的内容代表什么?
BitmapDescriptor 得到的百度地图 Marker 显示模糊
SQL添加记录的数据来源于同一个表
Session没有更新
redis java 保存对象,为什么多用序列号,而不直接用redis提供的hash
python wifi模块使用 出现错误。
php 为什么常量可以用数组定义 静态变量却不能