私はReact Nativeを初めて使用し、提供されたFetch APIを適切に利用する方法を混乱させています。Reactネイティブコンポーネントの取得呼び出しを行うタイミング
コール自体(ここで概要を説明したように:http://facebook.github.io/react-native/docs/network.html)は簡単ですが、正常な応答をログアウトすることはできますが、データをレンダリングする時間が来ると未定義です。
空の 'movies'配列を定義し、componentDidMount()から 'setState'を呼び出して置き換えて、再レンダリングをトリガーすると思います。この仮定は間違っていますか?
次のエラーで結果以下のコードサンプル:任意の助けを事前に
'undefined is not an object (evaluating 'allRowIDs.length')
ありがとう!
あなたがListView.DataSource
にデータを配置する必要があるためです
import React, { Component } from 'react';
import { AppRegistry, ListView, Text, View } from 'react-native';
class ReactNativePlayground extends Component {
constructor() {
super();
this.state = {
movies: []
}
}
componentDidMount() {
fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
movies: responseJson.movies
})
})
.catch((error) => {
console.error(error);
});
}
render() {
return (
<View>
<Text>test</Text>
<ListView
dataSource={this.state.movies}
renderRow={(row) => <Text>{row.title}</Text>}
/>
</View>
)
}
}
AppRegistry.registerComponent('ReactNativePlayground',() => ReactNativePlayground);
'this.state.movies '' render'メソッドの 'return'ステートメントの前に' '' 'メソッドを呼び出すかどうかを確認してください配列やオブジェクトを記録するかどうかを確認してください –