RealtimeDatabase Read data via Java Script

0

I have the following JSON

  "colecao" : {
    "id" : {
      "subid1" : 2,
      "subid2" : 1
    }
  }

Use the following commands to get realtime data

    var dbrealtime = firebase.database(); 
    var query = dbrealtime.ref('colecao');
    query.on('value', function(snapshot) {
    console.log(snapshot.val().id);

});

If I do it will get the value "2";

console.log(snapshot.val().id.subid1);

I'd like to make a foreach and show the two values they have in the id without having to reference subid1 and subid2.

Example:

2

1

    
asked by anonymous 07.10.2018 / 15:05

1 answer

0

You can use Jquery to do this, with the following code:

$.each(snapshot.val().id, function(index, element) {
    console.log(element);
});

You can read the documentation for this function here:

link

    
07.10.2018 / 15:20