React Native Expo:如何使用Firebase查询集合中多个文档中的选择字段?

问题描述 投票:0回答:1

我目前正在尝试使用Firebase在应用程序上同步我的宠物清单,以便可以这样显示:

(图像)姓名年龄避难所

enter image description here

但是,我很难对此进行编码,因为我只能从一个文档中进行查询,如下面的代码所示:

    db.collection("pets").doc("dog01").get()
        .then(doc => {
              console.log(doc.data());
              this.setState({ 
                name: doc.data().name,
                shelter: doc.data().shelter,
                gender: doc.data().gender,
                age: doc.data().age,
                breed: doc.data().breed,
              });
        })
        .catch(err => {
          console.log('Error getting documents', err);
        });

有什么解决方法吗?

reactjs firebase react-native google-cloud-firestore expo
1个回答
0
投票

您需要从集合中查询文档,然后在组件的渲染中显示(您使用的是Class Component的,对吗?)。>>

首先,不要忘记声明state

© www.soinside.com 2019 - 2024. All rights reserved.