以下代碼顯示來自我的數(shù)據(jù) API 的標(biāo)記列表,在標(biāo)記單擊時,它使用用戶單擊的標(biāo)記的 ID 設(shè)置 selectedMarker 狀態(tài)。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 }現(xiàn)在我已將標(biāo)記 ID 保存為狀態(tài),如何使用 .map 函數(shù)根據(jù)其 ID 顯示有關(guān)該特定標(biāo)記的信息?
根據(jù) ID 顯示特定數(shù)據(jù)
回首憶惘然
2021-10-07 10:38:05