简体   繁体   English

从 Firestore 调用 ReactNative FlatList 数据 - 无法做到

[英]Calling ReactNative FlatList data from Firestore - Unable to do it

I am able to hardcode a FlatList that pulls information from a randomuser.org dataset.我能够对从 randomuser.org 数据集中提取信息的 FlatList 进行硬编码。 However, I'm totally unable to pull any data from my Firestore database - it just displays a blank page in Expo without any error warnings.但是,我完全无法从我的 Firestore 数据库中提取任何数据——它只是在 Expo 中显示一个空白页面,而没有任何错误警告。 I've been stuck on this for a few days and the more I search around the more confused I seem to be.我已经坚持了几天了,我搜索得越多,我似乎就越困惑。 I'm new to coding so I apologise if this is a really basic question.我是编码新手,所以如果这是一个非常基本的问题,我深表歉意。 I've kept the picture of my code simple with just the FlatList in the App,js file - but as soon as I try to return data from Firestore it is just blank.我只使用 App,js 文件中的 FlatList 使我的代码图片保持简单 - 但是一旦我尝试从 Firestore 返回数据,它就只是空白。 no matter what I seem to do.不管我做什么。 Thank you谢谢

Image 1图 1

Image 2图 2

First of all I never seen any tries to fetch anything from Firebase Console UI.首先,我从未见过任何尝试从 Firebase 控制台 UI 获取任何内容的尝试。 If you are following any tutorial please add the link to it.如果您正在学习任何教程,请添加指向它的链接。

Anyway, if I understand that you want to use fetch to get data.无论如何,如果我知道您想使用fetch来获取数据。 Not sure if this is possible with it, for sure not using url http://firebase.google.com/project/project-name/firestore/data as this is link to Firestore GUI and you will not be able to get anything useful from that.不确定这是否可行,确保不使用 url http://firebase.google.com/project/project-name/firestore/data因为这是指向 Firestore GUI 的链接,您将无法获得任何有用的信息从此。

If you want to get data from Firestore you have to use Firebase API .如果要从 Firestore 获取数据,则必须使用Firebase API Thesimplest read example can be found in the documentation. 最简单的阅读示例可以在文档中找到。 So you have to use your database structure (means collections and documents) and create reference to what you want to pull.因此,您必须使用您的数据库结构(意味着 collections 和文档)并创建对您想要提取的内容的引用。 Than use some method like get() .比使用诸如get()之类的方法。 I suggest to get familiar with whole API reference .我建议熟悉整个 API参考

Finally if you want to use it in react you have to integrate the API with your app.最后,如果您想在反应中使用它,您必须将 API 与您的应用程序集成。 For this there is tones of nice articles about it.为此,有很多关于它的好文章。 I think this one is nice to start with.我认为这是一个很好的开始。

PS. PS。 Please do not paste screenshots with your code.请不要将屏幕截图粘贴到您的代码中。 Use code snippets to help others reproduce the issue and play with it.使用代码片段来帮助其他人重现问题并解决问题。 There is nice tutorial how to ask question on SO.有很好的教程如何在 SO 上提问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM