【发布时间】:2019-08-12 08:34:43
【问题描述】:
需要使用自定义键(索引或产品 ID)更新购物车状态
state = {
cart:[
0:{
"productID": 1234,
"size",''
"color":'',
"price":1599
},
1:{
"productID": 1162,
"size",''
"color":'',
"price":2899
},
};
当客户选择颜色购物车项目的值需要更新时
handleChange = input => e => {
this.setState({ [input]: e.target.value });
};
render(){
<NativeSelect
input={<Input name="color" />}
// cart[item.productId]
onChange={handleChange(this.state.cart[0].color)}
>
<option value="">---</option>
<option value="red">red</option>
<option value="green">green</option>
</NativeSelect>
}
我只需要语法或方法如何将我的商品指向购物车并更新状态
【问题讨论】:
-
嗨,Djordje,请尝试下面的解决方案,如果有帮助,请告诉我。