Skip to content

Instantly share code, notes, and snippets.

@amiel
Created October 2, 2013 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiel/6798366 to your computer and use it in GitHub Desktop.
Save amiel/6798366 to your computer and use it in GitHub Desktop.
grouping items in an Ember.ArrayController
<table>
{{#each category in categories}}
<thead>
<tr>
<th class="large">
{{category.name}}
</th>
</tr>
<tr>
<th>Line Item</th>
</tr>
</thead>
<tbody>
{{#each line_item in category.line_items}}
{{ render "line_item" line_item }}
{{/each}}
</tbody>
{{/each}}
</table>
App.LineItemsController = Ember.ArrayController.extend
categories: (->
@get('model').mapBy('category').uniq().map (category) =>
Ember.Object.create
name: category
line_items: @get('model').filterBy 'category', category
).property('@each.category')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment