Multiple Models in a View

How to use multiple models in a view? Retrieve another data and set to controller in Route’s setupController method.

1
2
3
4
5
6
7
8
9
10
model: ->
  return Place.places()

setupController: (controller, model) ->
  #model is the result of Place.places()
  controller.set 'content', model

  #another data
  categorys = Category.categorys()
  controller.set 'categorys', categorys

I create CategoryView and bind data to it in template

{{#each category in categorys}}
  {{#view CategoryView contentBinding="category"}}
    {{category.name}}
  {{/view}}
{{/each}}

{{#each place in content}}
  {{place.name}}
{{/each}}

CategoryView code: I use classNameBinding to auto update class when status is changed.

1
2
3
4
5
6
7
8
9
10
CategoryView = Ember.View.extend
  classNameBindings: ['getClass']
  status: true

  getClass: ( ->
    if this.get('status')
      return "btn-info"
    else
      return "btn-default"
  ).property('status')

Comments