I\'m trying to achieve a \"group by\" functionality in Ember.js and its proving more difficult than I originally thought.
[{date: \'2014-01-15T16:22:16-08:00\',
You can use Ember.computed.groupBy
like this:
((Ember) ->
# Example:
#
# productsByCategory: Em.computed.groupBy 'products', 'category'
#
# each view.productsByCategory
# category.name
# each content
# content.name
#
Ember.computed.groupBy = (collection, groupBy) ->
dependentKey = "#{collection}.@each.#{groupBy}"
Ember.computed dependentKey, ->
result = []
@get(collection).forEach (item) ->
unless result.findBy groupBy, item.get(groupBy)
data = content: []
data[groupBy] = item.get(groupBy)
result.pushObject Ember.Object.create(data)
result.findBy(groupBy, item.get(groupBy)).get('content').pushObject item
result
) Ember