我必須文件:eventsMapPage.js (main) 和 Maps.js(child)。getEvents = async () => {const requestResponse = await request(BASE_API_URL + "/api/events", { method: "GET", headers: {}, body: {} });this.state.eventList = requestResponse.data;console.log('getEvents');console.log(this.state.eventList);}//fetching data from api in parent```getEvents = async () => {const requestResponse = await request(BASE_API_URL + "/api/events", {method:"GET", headers: {}, body: {} }); this.state.eventList = requestResponse.data;}```//Sent state with fetched data```<GoogleApiWrapper eventList={this.state.eventList} ></GoogleApiWrapper>```//Send data```let markerList = []export class MapContainer extends Component { constructor(props) { super(props); this.state = {}; markerList = props.eventList;```//I want to put this fetched data to Markers```return ( <Map google={google} zoom={14} onClick={this.onMapClick} style={mapStyles} initialCenter={initialCenter}> { markerList.map(marker => { return ( <Marker key={marker.id} onClick={this.onMarkerClick} title={marker.title} name={marker.name} position={{ lat: marker.lat, lng: marker.lng }} />...```實際上,我只想在我的谷歌地圖中使用來自 web api 的標記。當我用數據發送硬編碼的 arrar{} 時,它可以工作,但是當我用這個 api 發送時。首先渲染孩子,然后從 api 中獲取。所以我的地圖上沒有任何標記。我讀到:a)componentWillMountb) 谷歌地圖上的事件,如 onChange 或 onBoundsChanged,但我不知道如何在我的項目中使用它。通常在 WPF 中我有綁定,這里谷歌地圖工作很奇怪。JS 應該在數據來的時候自動刷新。如何從api獲得標記?
如何通過 api 獲取數據并用它呈現子組件 - 反應谷歌地圖
海綿寶寶撒
2021-06-28 09:43:07
