我试图只更新数组状态中的一个元素,但我不确定如何更新.
State
constructor(props) {
super(props);
this.state = {
markers: [],
};
}
Setting the state
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第四个元素的键,我该怎么做?
谢谢