它总是在加载,没有内容显示。
应用程序.js
import React, { Component } from 'react';
import { ActivityIndicator, FlatList, Text, View, StyleSheet } from 'react-native';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: true
}
}
componentDidMount() {
return fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
// let ds = new FlatList.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.setState({
isLoading: false,
dataSource: ds.cloneWithRows(responseJson.movies),
}, function() {
// do something with new state
});
})
.catch((error) => {
console.error(error);
});
}
render() {
if (this.state.isLoading) {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ActivityIndicator />
</View>
);
}
return (
<View style={{flex:1,justifyContent:'center'}}>
<FlatList
data={this.state.data}
keyExtractor={this._keyExtractor}
renderItem={({item}) => <Text> {item.Begin} </Text> }
/>
</View>
);
}
}
DataSource
使用and的目的是什么cloneWithRows
?我理解正确吗 - 你需要获取一个对象并输出一个数组movies
?您可以将数组直接传递给组件:小吃