How do I get an array of objects from Firebase?
Date : March 29 2020, 07:55 AM
it helps some times When I get all items from a JSON table in Firebase, it returns them as object of objects. , You can order them into an array on the client-side. var query = this.refJob.orderByChild('status').equalTo('Active');
var array = [];
query.on('value', (snap) => {
snap.forEach((child) => {
var item = {};
item._key = snap.key();
array.push(item));
});
});
|
Sort array by distance near user location from firebase
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , This is a complex process, requiring multiple steps. I'll try to explain the steps, but you'll have to do quite some work to turn it into a functioning solution. Geocoding
|
Ordering objects in firebase Array in ngRepeat using elements stored at a different location in the database
Date : March 29 2020, 07:55 AM
like below fixes the issue I want to order the objects in my array in the ngRepeat using values stored in firebase under a different thread. See code and images. I am currently using the following code, it doesn't give errors but neither does it order my objects according the the amount of votes: , I solved the problem using a function. See code below: In the HTML: ng-repeat="for in For | orderBy: orderFunc | limitTo: 30"
$scope.orderFunc = function(element){
order = -(dataVotes[element.ref].total) ;
return order
}
|
Creating an Array of JS objects from Firebase
Date : March 29 2020, 07:55 AM
Hope this helps Create the mestaz array only once outside the loop not a new instance every iteration of the loop var mestaz = []; /// create one array
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
var mesto = {
name: mesta[k].nazevmesta,
lat: mesta[k].lat,
lng: mesta[k].lng
};
// push each object to same array
mestaz.push(mesto);
}
// log whole array after adding all of the elements in the loop
console.log(mestaz);
|
Firebase: How to get array back rather than objects
Date : March 29 2020, 07:55 AM
To fix the issue you can do I am making a call to get a list of books I have setup in firebase with this call , Go over the Object keys and convert to Array of Objects using map. var obj = { a: { b : 2 }, c: { b : 2 } };
var arr_obj = Object.keys(obj).map(key => ({ [key]: obj[key] }));
console.log(arr_obj)
|