【发布时间】:2020-10-21 09:25:51
【问题描述】:
我正在尝试使用 React 更改另一个数组中的数组的值。
这是我的数组:
routes = [
{
id: 1,
points: [{id, address, status}, {id, address, status},]
},
{
id: 2,
points: [{id, address, status}, {id, address, status},]
},
]
以及我是如何设置的。当用户点击“接受”时,该特定点的状态应该会改变。
{routes.map((route, i) => (
<div>...</div>
{route.points.map((point, i) => (
<Button onClick={() => this.onAcceptClicked(route.points)>Accept</Button>
))}
))}
我在这里尝试更改值,但我遗漏了一些东西或做的一切都完全错误。该特定点的状态应设置为 2。
onAcceptClicked = (points) => {
const myNewArray = Object.assign([...points], {
[index]: {
...deliveryPoints[index],
status: 2
}
});
//this.setState({ points: myNewArray }); ... not sure how to do this part
}
【问题讨论】:
标签: javascript arrays reactjs react-native