我的代码遇到问题。我是本机反应的新手。 分派后,我无法在减速器中浏览对象。
我的动作:
export const updateConvertCurr = (listFav, id, amount) => async (dispatch) => {
try {
const obj = {};
_.forEach(listFav, async (value, key) => {
const convertKey = id + '_' + value.id;
const { data } = await axios.get('https://free.currencyconverterapi.com/api/v6/convert?q=' + convertKey + '&compact=ultra');
obj[value.id] = {num: value.amount};
});
dispatch ({
type: UPDATE_CURRENCY_SELECT,
payload: obj
});
}
catch (err) {
console.log(err);
}
};
我的减速器:
case UPDATE_CURRENCY_SELECT:
console.log('UPDATE_CURRENCY_SELECT');
let newState = {...state,
arr: state.arr.map(item => return {...item, amount: action.payload[item.id].value}),
currSelect: {...state.currSelect}
//currSelect: action.payload.currSelect
};
return {...newState};
action.payload [item.id] .value始终未定义...
有什么想法吗?谢谢!