我正在尝试在反应原生页面上显示一个城市的 zomato 餐厅集合。我正在使用 zomato API。在 zomato API 文档中,我使用的是“在城市中获取 zomato 收藏”下给出的请求 URL
下面是我的代码:
import React from 'react';
import { StyleSheet, Text, View, FlatList, Image, ActivityIndicator } from 'react-native';
import { Card, CardItem } from "native-base"
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
dataSource: [],
}
}
getUserFromApi = () => {
return (
fetch("https://developers.zomato.com/api/v2.1/collections?city_id=1", {
headers: {
'Content-Type': 'application/json',
'user-key': '2bf4669cad5a8230fd2b220a2d4a37b9'
}
})
.then(response => response.json())
.then(responseJson => {
this.setState({
isLoading: false,
dataSource: responseJson.collections.collection
})
})
.catch(error => console.log(error))
)
}
componentDidMount() {
this.getUserFromApi();
}
render() {
if (this.state.isLoading) {
return (
<View style={styles.progress}>
<ActivityIndicator
size="large"
color="#01CBC6"
/>
</View>
)
}
return (
<View style={{marginTop: 50}}>
<FlatList
data={this.state.dataSource}
keyExtractor={({ id }, index) => id}
renderItem={({ item }) => (
<Card>
<CardItem>
<View style={styles.container}>
</View>
<View style={styles.userInfo}>
<Text> collections_id: {item.collections_id}</Text>
</View>
</CardItem>
<CardItem>
<View style={styles.container}>
</View>
<View style={styles.userInfo}>
<Text>title: {item.title}</Text>
</View>
</CardItem>
<CardItem>
<View style={styles.container}>
</View>
<View style={styles.userInfo}>
<Text>description: {item.description}</Text>
</View>
</CardItem>
</Card>
)}
/>
</View>
);
}
}
我没有收到任何错误,但我的屏幕是空白的。我的屏幕上没有输出。我无法理解我在代码中哪里出错了