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())
If I give the following code it does not find such value outside the firebase function.
console.log(getMarker()[0].id)
arrMarkers
is local, only works within the functiongetMaker
– Valdeir Psr
@Valdeirpsr I’ve used as a global, dai does not work.
– user50860