Does Firebase not allow you to use get and set in query information?

Asked

Viewed 47 times

2

I’m trying to use the get and set methods with javascript in firebase querys..

It does not allow me to use get() because it does not access the array and is giving error or lenght 0.

Why it happens and how it should be done?

Sample code:

// BUSCAR NO FIREBASE
function getMarkersFB(){
    let arrMarkers = new Array();
    let databaseROOT = firebase.database().ref('aliansce/maps/');
    databaseROOT.on('child_added', (mapsKeys) => {

        let databaseMAPS = databaseROOT.child('' + mapsKeys.key + '/markers/');
        databaseMAPS.on('child_added', (markersKey) => {

            let databaseMARKERS = databaseROOT.child('' + mapsKeys.key + '/markers/' + markersKey.key);
            databaseMARKERS.on('value', (markersChildsKeys) => {
                //console.log(markersChildsKeys.val())
                arrMarkers.push({
                    id: markersChildsKeys.val().markerID,
                    points: markersChildsKeys.val().markerPoints,
                    title: markersChildsKeys.val().markerTitle
                });

            });
        });
    });

    setMarker(arrMarkers)
    console.log(getMarker())

inserir a descrição da imagem aqui

If I give the following code it does not find such value outside the firebase function.

console.log(getMarker()[0].id)

inserir a descrição da imagem aqui

    1. Returns nothing because the function returns nothing, except that the is an asynchronous method of Firebase; 2. The variable arrMarkers is local, only works within the function getMaker
  • @Valdeirpsr I’ve used as a global, dai does not work.

No answers

Browser other questions tagged

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