2014-01-21 38 views
2

我试图渲染项目列表并为每个项目提供选择输入。 select的选项来自商店,所以当传递给Ember.Select时将会是一个承诺。这可能吗?如果内容发生变化,它看起来不会再显示,所以看起来我可能必须这样做。Can Ember.Select呈现对内容的承诺

我的模板(略)

{{#each fruitBins}} 
    <tr> 
     <td>{{id}}</td> 
     <td> {{view Ember.Select 
          content=fruitTypes 
          optionLabelPath="content.name" 
          optionValuePath="content.id" 
          prompt="Select a Fruit Type" 

          }} 
     </td> 
    </tr> 
{{/each}} 

fruit_bins_controller.js:

... 
fruitTypes: function() { 
    return this.store.find('fruitType'); 
}.property(), 

当选择呈现的是提示,出现的唯一的事。

恩贝尔:1.3.1,数据:1.0.0.beta4

+0

有你为什么'fruitTypes'作为承诺将在控制器处理一个合适的理由?为什么不使用路线? – edpaez

+0

你是否打算将'fruitTypes:'函数移动到路由中?只是澄清。 – claptimes

+0

是的。将'this.store.find('need_type'))'移动到路由的'model'钩子中,这样Ember就会一直等到承诺完成,然后您可以使用'setupController'钩子中的值设置控制器。 – edpaez

回答

2

事实证明我是错的理解我的问题。

作为@edpaez建议的更新,我认为我的代码与惯例对齐。我增加了以下我的路线:

model: function() { 
    return Em.RSVP.hash({ 
    content: this.modelFor('<the parent element>'), 
    fruitTypes: this.store.find('fruitType') 
    }); 
}, 
setupController: function(controller, model) { 
    controller.setProperties(model); 
} 

我仍然有同样的问题,但并发现(忘了),使用#each改变我的背景。

的解决方案是包裹#each

{{#with this as context}} 
    {{#each fruitBins}} 
    <tr> 
    <td>{{id}}</td> 
    <td> {{view Ember.Select 
         content=context.fruitTypes 
         optionLabelPath="content.name" 
         optionValuePath="content.id" 
         prompt="Select a Fruit Type" 

         }} 
    </td> 
    </tr> 
    {{/each}} 
{{/with}}