在{{each}}帮助器中,Ember:{{link-to}}帮助器错误

时间:2015-01-04 23:39:16

标签: ember.js

link-to助手返回以下错误:

Uncaught Error: each doesn't match link-to - 5:10

模板:

<script type="text/x-handlebars" id="actions">
  <div class='container-fluid'>
    <div class="row">    <!--  -->
      <div class="col-md-6 col-lg-4">    <!--  -->
        {{#each action in model}}
          {{link-to 'action' action}}{{action.id}}{{/link-to}}
        {{/each}}
        {{outlet}}
      </div>       
    </div>
  </div> 
</script>

路由器:

App.Router.map(function() {
  this.resource('application', function() {
    this.resource('actions', function() {
      this.resource('action', { path: '/:action_id'});
    });  
});

路线:

App.ActionsRoute = Ember.Route.extend({
  model: function() {
    return this.store.findAll('action');
    //return this.modelFor('user').get('actions');
  },

  setupController: function (controller, model) {
    controller.set('model', model);
  },

});  

我找不到有什么问题。

1 个答案:

答案 0 :(得分:6)

这是一个非常小的错误。使用eachlink-to之类的块助手时,需要使用前面的#来调用它们,例如使用{{#each}}。由于您在起始link-to上缺少该内容,因此解析器会看到{{/link-to}},并注意到它当前正在使用each - 块,但这些内容并不匹配。只需在您的首页&#39;链接前添加一个#。它应该工作正常。

{{#each action in model}}
    {{#link-to 'action' action}}{{action.id}}{{/link-to}}
{{/each}}