Ember.js: Rendering template with parameters

233 Views Asked by At

I'm a novice in ember and I'm building a test app with ember.js. It's a calendar. I need to group events by day of week. In my controller I have something like this:

Calendar.WeekController = Ember.ArrayController.extend
  sunday: ( ->
    @get('content').filterProperty('dayOfWeek', 0)
  ).property('[email protected]')
  monday: ( ->
    @get('content').filterProperty('dayOfWeek', 1)
  ).property('[email protected]')

# for all days of week

In my template:

ul
  each sunday
    li = description

I think that looks wrong, but I have no idea how to improve this. Is there a better way to do this?

1

There are 1 best solutions below

0
On BEST ANSWER

Create your groups dynamically.

Calendar.WeekController = Ember.ArrayController.extend
  groups: (->
    content = @get('content')
    for dayOfWeek in [0..6]
      Ember.Object.create
        dayOfWeek: dayOfWeek
        events: content.filterProperty('dayOfWeek', dayOfWeek)
  ).property('[email protected]')

In your template:

each groups
  / TODO: Convert number to day name, for example, Sunday, Monday, etc.
  h1 = dayOfWeek
  ul
    each events
      li = description