如何在ember js中渲染多个模型

时间:2013-03-23 19:01:15

标签: ember.js

我有3种型号货币,收入和收入操作。我想在某些路线上渲染它们。做正确的方法是什么?如何在一个页面上渲染三个模型?

UPD:此模型之间没有任何关联。

route.js.coffee

@route 'addincome', { path: 'operations/addincome' }

EmberMoney.AddincomeRoute = Ember.Route.extend
  model: ->
    EmberMoney.IncomeOperation.find()

模板/ addincome.handlebars

<div class="row container-bg"><br>
<div class="span6">
  <ul>
      {{#each operation in controller}}
        <li>{{operation.sum}}</li>
      {{/each}}
  </ul>
</div>
<div class="span6">
  {{outlet}}
</div>
</div>

// I want to render here more models! For example:

  <ul>
      {{#each income in incomes}}
        <li>{{income.name}}</li>
      {{/each}}
  </ul>

1 个答案:

答案 0 :(得分:1)

未经测试,但在路线的setupController中你可以:

# excuse the coffeescript...
setupController: (controller) ->
  controller.set('incomes', App.Income.find());

然后在你的模板中:

<ul>
  {{#each income in controller.incomes}}
    <li>{{income.name}}</li>
  {{/each}}