Firebase with Javascript - Get the child's title from the database

0

Hi, I need to capture the name of the childs 10de2017 and 11de2017 from the following image database:

InitiallyItriedthefollowing:

vardatasWO=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 this case it returns the names of childs that are inside 10de2017 and 11de2017 .

I already tried to use child.parent.key (which would logically return 10de2017 and 11de2017) but I get an error message in the console: Cannot read property 'parent' of undefined . I need to list those nodes to automatically add them to a select html.

    
asked by anonymous 03.11.2017 / 19:17

1 answer

0

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

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


datasWO.once("value", function (snapshot) {
    snapshot.forEach(function (child) {
        console.log(child.key);
    });
});
    
09.11.2017 / 17:42