【发布时间】:2020-02-08 18:56:48
【问题描述】:
- 列表项
我有一个具有这种结构的 redux 商店
const INITIAL_STATE = {
currentData: [
{
title: 'Total Insurance Bought',
img: 'insurance-bought.svg',
bg: 'insurance-shield',
data: '',
},
{
title: 'Total Amount of Claims',
img: 'amount of claims icon.svg',
bg: 'amount-of-claims',
data: '',
}
]
}
这是我的reducer函数的当前结构
const summaryReducer = (state = INITIAL_STATE, action ) => {
switch(action.type){
case 'SET_SUMMARY_DATA':
return {
...state,
currentData: {
...state.currentData,
data: action.payload
}
}
default:
return state
}
}
我想将 action.payload 中这个数组的值传播到初始状态的每个数据属性中,同时返回整个状态。
[ 0 , 20000 ]
我希望我的输出是
const INITIAL_STATE = {
currentData: [
{
title: 'Total Insurance Bought',
img: 'insurance-bought.svg',
bg: 'insurance-shield',
data: '0',
},
{
title: 'Total Amount of Claims',
img: 'amount of claims icon.svg',
bg: 'amount-of-claims',
data: '20000',
}
]
}
【问题讨论】:
-
[ 0 , 20000 ] - 这些值中的哪一个对应于
Total Insurance Bought和Total Amount of Claims?你希望你的最终输出是怎样的? -
0 应该去 Total insurance and 20000 to total amount of claim
-
我已经发布了我的解决方案,希望对您有所帮助!
标签: javascript reactjs object redux