简体   繁体   中英

Fetching data from firebase web

I am trying to fetch the data for website using java script. Problem I am getting is that I am unable to get the key of Users-->Customers-->Key-->(name, phone). I am unable to find a syntax of it

数据库映像

Code I am trying is

 var fireheading = document.getElementById("fireHeading");


var firebaseHeadingRef = firebase.database().ref().child("Users").child("Customers").child(uid).child("name");



firebaseHeadingRef.on('value', function(datasnapShot){
    fireHeading.innerText = datasnapShot.val();
});

To get data from Firebase in javascript, you would do this:

var fireHeading = document.getElementById("fireHeading");
// "key" is the customer key
var ref = firebase.database().ref("Users/Customers/" + key);

ref.once("value", function(snapshot){
// Contains all data from Firebase
var data = snapshot.val();
// Has customer name
var customerName = data.Name;
// Has customer phone
var customerPhone = data.Phone;

// Append data to view
fireHeading.innerText = customerName;

});

This should work.

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