以下代码显示来自我的数据 API 的标记列表,在标记单击时,它使用用户单击的标记的 ID 设置 selectedMarker 状态。getPosts() { axios .get("mydataAPI") .then(response => { this.setState({ posts: response.data.response }); }); }///This code is then returned to the user with MapView to display a list of markers on map, when a user clicks a marker the ID of that marker is stored in state /// {this.state.posts.map((user, index)=> { return ( <MapView.Marker key={user.ID} coordinate={{latitude: user.lat, longitude: user.lng}} onPress={() => {this.setState({selectedMarker: user.ID})}} title={user.category} description={Moment(user.post_date).fromNow(), user.category, user.address} image={require('../images/yes.png')}/> ); })}//// will display ID of marker user selected ////{ this.state.selectedMarker }现在我已将标记 ID 保存为状态,如何使用 .map 函数根据其 ID 显示有关该特定标记的信息?
添加回答
举报
0/150
提交
取消