Firebase with Javascript - Get the Child title from the database

Asked

Viewed 352 times

0

Good people, I need to capture with javascript the name of Childs 10th of 2017 and 11de2017 from the following image database:

inserir a descrição da imagem aqui

Initially I tried as follows:

var datasWO = firebase.database().ref().child("WO"); //acesso o primeiro child depois do ref.
    datasWO.on("child_added", function (snap2){
        snap2.forEach(function(childSnap){
            console.log(childSnap.key); //e então mostro o nome deles
        });

})

In that case he returns the names of childs who are within 10de2017 and 11de2017.

inserir a descrição da imagem aqui

I’ve tried using the child.parent.key (That logically would return me 10de2017 and 11de2017) but I get on the console an error message: Cannot read property 'parent' of undefined. I need to list these nodes to automatically add them in a select html.

1 answer

0


I found the solution, the problem was in Child_added. Using the Value i can get the key from the first Child after the WO.

var datasWO = firebase.database().ref("WO");


datasWO.once("value", function (snapshot) {
    snapshot.forEach(function (child) {
        console.log(child.key);
    });
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.