Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 从mlab获取react native中的数据_Reactjs_React Native_Backend_Mlab - Fatal编程技术网

Reactjs 从mlab获取react native中的数据

Reactjs 从mlab获取react native中的数据,reactjs,react-native,backend,mlab,Reactjs,React Native,Backend,Mlab,我正在尝试学习使用apikey从服务器获取数据。我用这个创建了一些文档。 在文档中,我无法在代码中列出项目 从“React”导入React;导入{FlatList,ActivityIndicator, 文本,视图}来自“react native” 导出默认类FetchExample扩展React.Component{ 建造师(道具){ 超级(道具); this.state={isLoading:true} componentDidMount(){ 返回获取('https://api.mlab.

我正在尝试学习使用
apikey
从服务器获取数据。我用这个创建了一些文档。 在文档中,我无法在代码中列出项目

从“React”导入React;导入{FlatList,ActivityIndicator, 文本,视图}来自“react native”

导出默认类FetchExample扩展React.Component{
建造师(道具){
超级(道具);
this.state={isLoading:true}
componentDidMount(){
返回获取('https://api.mlab.com/api/1/databases/ibrhmklnc/collections/kitap?apiKey=xRw1H6NNZZnyeZArU5L8oUoVcsFb6tpf')
.then((response)=>response.json())
.然后((responseJson)=>{
这是我的国家({
孤岛加载:false,
数据来源:responseJson.movies,
},函数(){
});
})
.catch((错误)=>{
控制台错误(error);
});   }
render(){
if(此.state.isLoading){
返回(
)
}
返回(
{item.title},{item.releaseYear}
keyExtractor={({id},索引)=>id}
/>
);   } }

以下是API的完整响应

[
    { 
        _id: { '$oid': '5be7260efb6fc072d46759b5' },
        movies: [ 
            { id: '1', title: 'Star Wars', releaseYear: '1977' },
            { id: '2', title: 'Back to the Future', releaseYear: '1985' },
            { id: '3', title: 'The Matrix', releaseYear: '1999' },
            { id: '4', title: 'Inception', releaseYear: '2010' },
            { id: '5', title: 'Interstellar', releaseYear: '2014' } 
        ] 
    }
]
如您所见,API响应是一个数组。因此,为了获取电影列表,您应该将数据源设置为:

dataSource: responseJson[0].movies,

下面是API的完整响应

[
    { 
        _id: { '$oid': '5be7260efb6fc072d46759b5' },
        movies: [ 
            { id: '1', title: 'Star Wars', releaseYear: '1977' },
            { id: '2', title: 'Back to the Future', releaseYear: '1985' },
            { id: '3', title: 'The Matrix', releaseYear: '1999' },
            { id: '4', title: 'Inception', releaseYear: '2010' },
            { id: '5', title: 'Interstellar', releaseYear: '2014' } 
        ] 
    }
]
如您所见,API响应是一个数组。因此,为了获取电影列表,您应该将数据源设置为:

dataSource: responseJson[0].movies,