0

我有来自 FireBase 的模型的 Route 设置:

App.ApplicationRoute = Ember.Route.extend({
    model: function() {
    return EmberFire.Array.create({
      ref: new Firebase("https://some-database.firebaseio.com/shape")
    });
    },
    setupController: function(controller, model) {
    controller.set('model', model);
    }
});

在模板中,我使用#each 在视图中显示每个数组对象:

{#each controller}}
    {{#view App.ColorView}}
    <div>{{color}}</div>
    {{/view}}
{{/each}}

在视图中,我喜欢单击操作来删除特定颜色:

App.ColorView = Ember.View.extend({
      click: function() {
          var theColor = this.get('content');
        console.log(theColor);
      }
  }); 

目前,他的视图中显示了一个颜色列表,但是当我尝试访问属于该对象的模型属性时,我得到“未定义”。我需要做额外的设置吗?

4

1 回答 1

0

你可以通过使用contentBinding

{#each controller}}
    {{#view App.ColorView contentBinding=this}}
    <div>{{color}}</div>
    {{/view}}
{{/each}}
于 2013-11-27T20:40:55.247 回答