【发布时间】:2015-12-07 02:11:36
【问题描述】:
我需要从子组件中更改嵌套对象数组。该数组作为来自父组件的道具传递下来,我想在列表中找到一个项目并对其进行更改,这样当我返回父场景时,更改将被保存。我有以下代码,但出现此错误:undefined is not an object (evaluating \'this.state')。任何人都可以引导我朝着正确的方向解决这个问题吗?
submitChange() {
//update the cart list
//hide the panel
this.props.cartList.forEach(function(arrayItem) {
if(arrayItem.prod.product === this.state.name) {
arrayItem.quantityOrdered = this.state.quantity;
}
console.log(arrayItem.prod.product + " " + arrayItem.quantityOrdered)
})
console.log( " this item" + this.state.quantity + ", " + this.state.name)
//this.props.hidePanel()
}
【问题讨论】:
标签: javascript reactjs react-native