Reputation: 25
I am new in firebase, how can i read child as in the image to my web page anyone can tell me if there is a reference?
Upvotes: 1
Views: 672
Reputation: 618
If you want to get the value only when your data is in an object, then you can use
var ref = firebase.database().ref(); //creating referense path
ref.once("value").then(data=>{
let obj = data.val();
for (let key in obj) {
console.log(obj[key]);
}
})
Upvotes: 0
Reputation: 600126
If you want to read all colors of all nodes:
var ref = firebase.database().ref();
ref.once("value").then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
childSnapshot.forEach(function(colorSnapshot) {
console.log(childSnapshot.key+" - "+colorSnapshot.key+": "+colorSnapshot.val());
});
});
});
This prints:
-LOIECwM70... - 1: red
-LOIECwM70... - 2: blue
-LOIEssdh1... - 1: green
-LOIEssdh1... - 1: black
Upvotes: 2