React Native Firebase如何使用特定用户从表数组中获取数据

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

Db Scheme

我从(特定用户的)教师表中获取“ userId”,并根据该userId在“ tutorCopy”下创建一个表,那些接受“ [email protected]”服务的用户将保存其userId和useremail 。现在,当[email protected]登录到系统时,我想显示分配给他的电子邮件/人员的数量。到目前为止,这是我所做的,但无法访问useremail:

 componentWillMount(){
     var refx =firebase.database().ref("tutorCopy")
    refx.orderByChild("table").on("value", function(snapshot) {
        snapshot.forEach(function(data) {
            this.setState({ markers: Object.values(snapshot.val()) })
          //alert(data.useremail)
        });
      });
    }

此外,我也只想显示从tutor表到tutorCopy具有tutorId匹配项的用户电子邮件。

javascript firebase react-native firebase-realtime-database react-native-firebase
1个回答
1
投票

尝试以下操作:

 componentWillMount(){
     var refx =firebase.database().ref("tutorCopy")
    refx.on("value", function(snapshot) {
        snapshot.forEach((childSnapshot) => {
          childSnapshot.forEach((childSnap) =>{
           console.log(childSnap.val());
          });
        });
      });
    }

您需要迭代两次才能访问useremail,在这种情况下orderByChild("table")也不起作用,因为您不能再访问table节点,因为您需要再走一个节点,例如:

var refx =firebase.database().ref("tutorCopy")
refx.child(userId).orderByChild("table")
© www.soinside.com 2019 - 2024. All rights reserved.