我正在尝试更新数组状态中的一个元素,但我不确定如何做。
状态
constructor(props) {
super(props);
this.state = {
markers: [],
};
}
设置状态
setCurrentLocation() {
var root = this;
root.setState({
markers: [
...root.state.markers,
{
coordinate: {
latitude: parseFloat(root.state.currentLat),
longitude: parseFloat(root.state.currentLon)
},
key: root.state.currentLat,
image: pinCurrentLocation
},
],
});
}
如果我想要更改marker的第四个元素中的键,应该怎么做?
谢谢