我试图只更新数组状态中的一个元素,但我不知道如何做到这一点.
州
constructor(props) {
super(props);
this.state = {
markers: [],
};
}
Run Code Online (Sandbox Code Playgroud)
设置状态
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
},
],
});
}
Run Code Online (Sandbox Code Playgroud)
如果我想更改标记的第四个元素中的键,我该怎么做?
谢谢