我正在使用ComponentDidMount()中的提取功能从API提取示例数据。提取后,我想在表格视图中显示它。但是我在模拟器中遇到错误,指出终端中的捆绑包错误:
无法加载捆绑包
下面是代码:
import React from 'react';
import { FlatList, ActivityIndicator, Text, View } from 'react-native';
import { ListItem } from 'react-native-elements';
export default class FetchExample extends React.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) => {
this.setState({
isLoading: false,
dataSource: responseJson.movies,
}, function(){
});
})
.catch((error) =>{
console.error(error);
});
}
render(){
if(this.state.isLoading){
return(
<View style={{flex: 1, padding: 20}}>
<ActivityIndicator/>
</View>
)
}
return(
<View style={{flex: 1, paddingTop:20}}>
<FlatList
data={this.state.dataSource}
renderItem={({item}) => (
<ListItem
title={item.title} releaseYear={item.releaseYear}
/>
)}
keyExtractor={({id}, index) => id}
/>
</View>
);
}
}