Firebase数据库查询

时间:2017-05-05 11:05:42

标签: javascript firebase firebase-realtime-database

这里我将senderId检索为sID,将recieverId检索为rID。但在检索后,我无法在连接时访问这两个id。如何在此查询外部访问这两个id。请帮忙。

以下是代码

var ref = firebase.database().ref("cUsers");                                  
ref.orderByChild("email").equalTo(senderEmail).on("child_added", function (snapshot){
      var sID = snapshot.val().uid;
      alert(sID);
    });
                                    ref.orderByChild("email").equalTo(email).on("child_added", function (snapshot) {
      var rID = snapshot.val().uid;
      alert(rID);
    });

var chatUsers=sID+"_"+rID;

1 个答案:

答案 0 :(得分:0)

这应该有用。

var sID = '';
var rID = '';

var ref = firebase.database().ref("cUsers");                                  
ref.orderByChild("email").equalTo(senderEmail).on("child_added", function (snapshot){
    sID = snapshot.val().uid;
    alert(sID);
});
ref.orderByChild("email").equalTo(email).on("child_added", function (snapshot) {
    rID = snapshot.val().uid;
    alert(rID);
});

var chatUsers=sID+"_"+rID;