我正在尝试将新项目推入State array
of objects
,面临一些问题。下面是我的代码。我确定我出了点问题
constructor(props) {
super(props);
this.state = {
bill: []
};
}
componentWillReceiveProps(nextProps, nextState) {
if (nextProps.bills !== this.props.bills) {
let billsObj = nextProps.bills
billsObj.map((billsObj) => {
var joined = this.state.bill.concat({billId:billsObj.id,checked:false});
console.log(joined, "joined", this.state.bill)
this.setState({
bill: [...this.state.bill, ...joined]
}, () => {
console.log(this.state.bill, billsObj.id)
})
})
}
}
在componentWillReceiverProps
我得到array
然后映射它以将值推入state
array
,但最后我在数组中只得到一个值,但props array
有 11 个值,我只在我的state array
. 希望能得到一些帮助。