我有一个连接到redux的组件,需要更新购物车组件中的项目和价格。
我尝试通过使用Object.assign(item, { isSelected: true })
进入操作创建者中的"它"来创建此功能,但是它正在打破所有复选框的更新功能,因为它很难将isSelected
属性设置为第一次属性。
我在实际组件中具有一个on Change功能,该功能附加到我的选择下拉downs中,我需要使用传播操作员在其中通过此功能,但我不确定如何做。
这是我当前的onchange函数:
<StyledSelect
value={selectedItem.id}
onChange={e => {
updateSelectedItem(e.target.value)
props.updateCart({
lineOne: 'Business',
lineTwo: 'addOns',
itemType: 'Item',
item: items.configurationItems.find(
obj => obj.id === e.target.value
)
})
}}
>
更新购物车功能作为动作创建者的一部分
export function updateCart({
lineOne, lineType, itemType, item
}) {
return {
type: UPDATE_CART,
payload: {
lineOne,
lineTwo,
itemType,
item
}
}
}
有什么想法?
弄清楚我需要做什么。将这种逻辑从我的动作创建者移到了onchange本身。下面的代码用于任何人的参考
<StyledSelect
value={selectedEquipment.id}
onChange={e => {
updateSelectedEqupment(e.target.value)
const item = items.configurationItems.find(
obj => obj.id === e.target.value
)
Object.assign(item, { isSelected: true })
props.updateCart({
lineOne: 'Business',
lineTwo: 'addOns',
itemType: 'Items',
item
})
}}
>