根据emailId匹配从Firebase数据库获取节点名称 [英] Getting node names from Firebase database based on emailId match

查看:108
本文介绍了根据emailId匹配从Firebase数据库获取节点名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下Json模式,可以使用哪种firebase查询来获取节点名称(0153,0154),我可以使用一次方法来获取名称(joel,vikram,sachin)

I have the below Json schema , what firebase query can I use to get the node name(0153,0154) , I am able to get the name(joel,vikram,sachin) using once method

 "EmployeeInfo":
        {
        "0153":
        {
          "Name":"Joel",
          "Dept":"Engineering",
          "Email":"joel@dept.com"
        },
        "0163":
        {
          "Name":"Vikram",
          "Dept":"Engineering",
          "Email":"vikram@dept.com"
        },
         "0173":
        {
          "Name":"Sachin",
          "Dept":"Engineering",
          "Email":"Sachin@dept.com"
        }

这是我的JavaScript函数:

Here is my javascript function :

function Call() {

  var dbref = new Firebase("https://logintrialapp.firebaseio.com/Employee/EmployeeInfo");
  var login = localStorage.getItem("Email");
  dbref
    .once("value")
    .then(function(snapshot) {
        snapshot.forEach(function(childSnapshot) {
            childData = childSnapshot.val();
            name = childData.Name;
            var n = login.localeCompare(name);
            console.log(name);

            if (n != 0) {
                var eid = snapshot.val();
                console.log("Hello" + eid);
            }
            console.log(snapshot.val());
        })
    })

使用此代码,我可以获取名称,但我想检索节点名称,可以使用什么查询基于emailid匹配条件获取节点名称

with this code I am able to get the names but I want to retrieve the node names , what query can be used to get the nodes names based on emailid match criteria

输出:

Joel
 Checkworks.html:50 Hello[object Object]
    Checkworks.html:55 Object {0153: Object, 0163: Object, 0173: Object}0153: ObjectDept: "Engineering"Email: "joel@dept.com"Name: "Joel"__proto__: Object0163: Object0173: 
    Object__proto__: Object
    Checkworks.html:44 Vikram
    Checkworks.html:50 Hello[object Object]
    Checkworks.html:55 Object0153: ObjectDept: "Engineering"
    Email: "joel@dept.com"Name: "Joel"__proto__: Object0163
    : Object0173: ObjectDept: "Engineering"Email: "Sachin@dept.com"Name: "Sachin"__proto__: Object__proto__: Object
    Checkworks.html:44 Sachin
    Checkworks.html:50 Hello[object Object]
    Checkworks.html:55 Object {0153: Object, 0163: Object, 0173: Object}

推荐答案

获取childSnapshot调用childSnapshot.key的密钥:

To get the key of the childSnapshot call childSnapshot.key:

.then(function(snapshot) {
    snapshot.forEach(function(childSnapshot) {
        childKey = childSnapshot.key; // Get the key of the child
        childData = childSnapshot.val();
        name = childData.Name;
        var n = login.localeCompare(name);
        console.log(name);

        if (n != 0) {
            var eid = snapshot.val();
            console.log("Hello" + eid);
        }
        console.log(snapshot.val());
    })
})

这篇关于根据emailId匹配从Firebase数据库获取节点名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆