コードにないものを教えてもらえますか?私はReactJSコンパイルに失敗しました: 'オブジェクト'が定義されていませんno-undef
(reactJSで初心者)... Googleマップマーカーに
目的は、すべてのオブジェクトを取得することです....夫婦の時間とエラー後のエラーのためにこれを行うために座標をしようとしている
class maps extends Component{
constructor(props){
super(props)
this.state = { Objects: [] }
}
render(){
{this.state.Objects.location.coordinates.map((item, i) => (
<Marker position= {{ lat: Objects[i].location.coodinates[0], lng: Objects[i].location.coordinates[1] }}/>
))}
const MyMapComponent = withScriptjs(withGoogleMap((props) =>
<GoogleMap
defaultZoom={2}
defaultCenter={{ lat: 40.6333333, lng: -8.65 }}
>
</GoogleMap>
))
return(
<div>
<MyMapComponent
isMarkerShown
googleMapURL="https://maps.googleapis.com/maps/api/js?key=AIzaSyCnQmNcHpzoytzm02Zf-inD6xxTdSRJdLg&v=3.exp&libraries=geometry,drawing,places"
loadingElement={<div style={{ height: `100%` }} />}
containerElement={<div style={{ height: `400px` }} />}
mapElement={<div style={{ height: `100%` }} />}
/>
</div>
)
}
componentDidMount(){
axios.get('https://api.ost.pt/traffic_events/?key=VMSBvXtmOixXVuaHqeyAxDEhQkbnJpXZBYjDufEu').then(response => {
const { Objects } = response.data
console.log(Objects)
this.setState({Objects})
})
.catch(error => {
console.log('Error fetching and parsing data', error);
});
}
}
These are the objects.coordinates from api data that I need to fetch
任意のヒントが理解されるであろう。どうもありがとう!
を、 'Objects'は空ですアレイ。これがプロパティに 'location'プロパティを持つと仮定するのは公正ではありません。あなたは何を達成しようとしていますか? – brandNew
あなたが反応した初心者なら、なぜ、「hello world」の代わりにこれを構築しようとしていますか? –
コンポーネントが最初にiircをレンダリングするときにデータがまだAxiosからロードされているため、 'Objects'がアクセスしようとする前に' Objects'がデータでいっぱいであるかどうかをチェックするチェックを追加する必要があります。 ) 'は通常十分です。 – Andy