简体   繁体   中英

How can I get specific data from firebase database which key value is e-mail?

I need to get specific data from firebase. My database look like this:

firebase 数据库用户节点

and I can get numara value correctly but my other keys which are E-mail and Kullanıcı Adı I can't get it with javascript because of - character and space. How can I solve it? I really need help.

Here my sample code:

      rootRef.on("value", function(snapshot) {

        var user = snapshot.val();
        console.log(user.numara, user."E-mail");
        

        snapshot.forEach(function(childSnapshot) {

         

         var childData = childSnapshot.val();
         //console.log(childData);
        });
       });

Here console.log(user) output.

控制台输出

It's hard to tell, because you don't provide a lot of information, but I noticed in your code, you're using user."E-mail" but your screen capture of the firebase UI actually shows the key as email

Could it be that?

If the problem is purely the - in the field name, you can use [] notation to get that specific field. Without Firebase that'd look like this:

var user = { "numara": "0536...", "E-mail": "ekslg..." };

console.log(user.numara, user["E-mail"]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM