Skip to content

Instantly share code, notes, and snippets.

@domchristie
Created February 12, 2013 23:27
Show Gist options
  • Save domchristie/4774472 to your computer and use it in GitHub Desktop.
Save domchristie/4774472 to your computer and use it in GitHub Desktop.
App.LineItemsController = Ember.ArrayController.extend({
groupedContent: (function() {
var lineItems = this.get('content');
if(!lineItems.get('isLoaded')) {
return null;
}
return lineItems.reduce(function(grouped, object, index, content) {
if(content.objectAt(index-1) &&
object.get('date').valueOf() == content.objectAt(index-1).get('date').valueOf()) {
grouped.get('lastObject').pushObject(object);
}
else {
grouped.pushObject(Em.A([object]));
}
return grouped;
}, Em.A([]));
}).property('content.isLoaded')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment