2014-01-21 42 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}}