我得到了一个阵列,并且需要检查,选择相同的项目,推送一个新的阵列并更新状态
const uniqueNumberEvent = 'z3werbfhgdhhsbz';
for (var j = 0; j < this.state.events.length; ++j) {
if (this.state.events[j].unique_number_event == uniqueNumberEvent) {
selectedTickets.push(this.state.events[j].tickets)
}
}
this.setState({
tickets: selectedTickets,
});
console.log(this.state.tickets);
但是此代码创建了新数组,但不更新状态