Best way to rollup/sum model data


#1

My model has some sales data by month and store location, something like this:

[
{ "month": "January",
  "store": "Texas",
  "amount": 150 },
{ "month": "January",
  "store": "Colorado",
  "amount": 220 },
{ "month": "January",
  "store": "New Mexico",
  "amount": 265 },
...
]

I’m trying to figure out the best way to roll up and sum the data, so it will look like this:

January Sales: 635
February Sales: ...

Similarly, I’ll need to show all the data summed up by store, like:

Colorado Sales: 1635
New Mexico Sales: ...

I’m not sure what the best way is for doing this in Ember. Any tips or suggestions are greatly appreciated! I’ve been digging through the guide and other websites, but haven’t found anything helpful for this.


#2

I would recommend using a computed property that is dependent on your sales data by month array. Then you can reformat your array to a hash, array, or whatever other data type you prefer to store your sums.