Javascript Firebase Firestore集合无法检索-反应本机
上下文:我在Firebase Firestore上有一个医生列表,我想检索与他们相关的数据 问题:应用程序的行为类似于集合为空,但它当前包含三名医生。我想检索对象列表中的数据,以便在应用程序中访问它们。另外,如果您对检索数据有任何其他想法,请告诉我,因为我还没有找到任何适合我的方法 下面是代码中有问题的部分:Javascript Firebase Firestore集合无法检索-反应本机,javascript,firebase,react-native,google-cloud-firestore,react-native-firebase,Javascript,Firebase,React Native,Google Cloud Firestore,React Native Firebase,上下文:我在Firebase Firestore上有一个医生列表,我想检索与他们相关的数据 问题:应用程序的行为类似于集合为空,但它当前包含三名医生。我想检索对象列表中的数据,以便在应用程序中访问它们。另外,如果您对检索数据有任何其他想法,请告诉我,因为我还没有找到任何适合我的方法 下面是代码中有问题的部分: componentDidMount(){ firebase.firestore().collection('doctors') .get()
componentDidMount(){
firebase.firestore().collection('doctors')
.get()
.then((querySnapshot
) => {
querySnapshot.forEach(snapshot => {
const doctors = []
snapshot.forEach(doc => {
const data = doc.data()
data.id = doc.id;
doctors.push(data)
})
this.setState({doctors :doctors})
})})
}
以下是我的Firebase的外观:
我找到了这个片段,我相信这正是您的使用案例:
// retrieve a collection
db.collection('documents')
.get()
.then(querySnapshot => {
const documents = querySnapshot.docs.map(doc => doc.data())
// do something with documents
})
你可以找到这个例子,还有其他例子。在每个代码段下,您可以找到原始源代码,以防需要为每个代码段提供更多上下文