Reputation: 895
I'm using Firebase to store the data, and want to display statistics information. As it seems Firebase doesn't support functions like groupBy, may I have advices on how to achieve it? Should it be done on client side?
Upvotes: 0
Views: 576
Reputation:
You have three basic options, two of which were mentioned in another answer.
Upvotes: 1
Reputation: 4067
You can use $extend to create new features that use the base classes, so you can transform your data.
They even have an example of creating a getTotal function at: https://github.com/firebase/angularfire/blob/master/docs/guide/extending-services.md#extending-firebasearray
The example
app.factory("ListWithTotal", ["$firebaseArray",
function($firebaseArray) {
// create a new service based on $firebaseArray
var ListWithTotal = $firebaseArray.$extend({
getTotal: function() {
var total = 0;
// the array data is located in this.$list
angular.forEach(this.$list, function(rec) {
total += rec.amount;
});
return total;
}
});
return function(listRef) {
// create an instance of ListWithTotal (the new operator is required)
return new ListWithTotal(listRef);
}
}
]);
Upvotes: 0
Reputation: 15363
Either do it client-side or if possible, store the total value in the db.
Upvotes: 0