2014-07-07 39 views
0

所以我在我的多個模型如何設置控制器Ember.JS

應用途徑

App.ApplicationRoute = App.AuthenticatedRoute.extend({ 
    model: function() { 
     return Ember.RSVP.hash({ 
      projects: this.store.find('project'), 
      departments: this.store.find('department'), 
     }); 
    }, 
    setupController: function(controller, model) { 
     controller.set('model', model); 
    } 
}); 

應用控制器

App.ApplicationController = Ember.ObjectController.extend({ 
    all_projects: Ember.computed.alias('model.projects'), 
    all_departments: Ember.computed.alias('model.departments'), 
}); 

得到這個然後我有這在我的模板中

<div class="col-xs-1" style="padding:0"> 
     {{view Ember.Select class="form-control cover-input" content=all_projects value=create_project}} 
    </div> 
     {{view Ember.Select class="form-control half-input" content=all_departments optionValuePath="content.id" optionLabelPath="content.department_name" value=create_department}} 

但是沒有任何內容出現在選擇框中。我也嘗試只是通過財產循環,如

{{#each all_departments}} {{department_name}} {{/each}}也沒有顯示任何東西。

回答

0

您的模型別名all_projects和all_departments將是一個數組對象。所以你應該爲你的ApplicationController擴展ArrayController而不是擴展ObjectController。

希望能解決加載Ember.Select視圖的問題。

下面給出了使用Ember.Select視圖渲染兩個模型的多個模型的基本示例。

JSBIN Ling

+0

確定那些是數組,但模型本身返回兩個數組的對象。所以'App.ApplicationController = Ember.ArrayController.extend'給了我一個錯誤,因爲它應該。 'Assertion Failed:ArrayProxy需要一個Array或Ember.ArrayProxy,但是你傳遞了對象'。 – user1952811

相關問題