我正在使用React-Native中的dataSource创建一个基本的ListView,其中包含我获取的数据.
class Movies extends Component {
render() {
if (this.state.dataSource.getRowCount() === 0) {
return (
<View style={styles.container}>
<Text>
loading....
</Text>
</View>
);
}
else {
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}
/>
</View>
);
}
}
constructor(props){
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
}),
};
}
componentWillMount() {
this.fetchData();
}
fetchData(){
fetch(HOT_MOVIES_URL)
.then((response) => response.json())
.then((responseData) => {
if (responseData) {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData),
});
}
})
.done();
}
}
Run Code Online (Sandbox Code Playgroud)
然而,我得到了一个 …
react-native ×1