How to retrieve data from Firebase Database?

前端 未结 3 560
春和景丽
春和景丽 2020-12-13 09:37

I\'m trying to create a simple program that takes name, mobile number and email address from user and then puts the data on Firebase Realtime Database.

There are 3 i

3条回答
  •  天命终不由人
    2020-12-13 10:13

    var reference = db.ref('/test/');
    reference.on('value', function(snapshot) {
    snapshot.forEach(function(userSnapshot){
    console.log(userSnapshot.val().url)
    document.getElementById('gmap').href = userSnapshot.val().location;
    document.getElementById('gimg2').src = userSnapshot.val().url;
    document.getElementById('name').innerHTML = userSnapshot.val().uid;
    

    I was facing the same issue. I wanted to read the data from the firebase realtime database and print the same on the web. The data I am reading is in the test document. Use the on() function to take the snapshot of it. Firebase provides you with a foreach loop to iterate over the data in the test document. The variable userSnapshot reads the value while looping. The variables location, url, uid are the keys in the test document.

    document.getElementById('gmap').href
    document.getElementById('gimg2').src 
    document.getElementById('name').innerHTML
    

    are the DOM element to print the data on the web

    See location 
     

    I hope this helps someone.

提交回复
热议问题