Reputation: 476
i know the question up there is confusing but here what i want to read from firebase in explained manner:
As it obvious from the image, i want retreive all circled three child's "route_name" and conosle log it in javascript. To do that i try like this:
var buses_Ref = firebase.database().ref('online_drivers/');
buses_Ref.on('child_added', function (data) {
console.log(data.val().route_name);
});
But it showing undefined
And if I tried to console log data it will showing this, which i think are the two children Jigjiga and Siinaay
console.log(data);
Upvotes: 0
Views: 64
Reputation: 598728
You have two nested dynamic child nodes under online_drivers
. By using child_added
Firebase takes care of one of those already, but you'll need to handle the other level in your callback code.
The easiest way to do this is with DataSnapshot.forEach()
:
buses_Ref.on('child_added', function (snapshot) {
snapshot.forEach(function(data) {
console.log(data.val().route_name);
})
});
Upvotes: 1