2013-07-29 40 views
0

我想簡單地使用路徑中定義的模型呈現一個Ember選擇視圖。數據來自燈具適配器。當這樣做時,我收到錯誤:Ember.CollectionView的內容必須實現Ember.Array - 你傳遞了App.AuthorsController。Ember選擇視圖錯誤:Ember.CollectionView的內容必須實現Ember.Array

我該如何解決這個問題?

見的jsfiddle:http://jsfiddle.net/cyclomarc/frvJZ/4/

(運行程序後,點擊「作者的鏈接轉到與authorsController數據作者航線上

CODE-HTML:

<script type="text/x-handlebars" data-template-name="application"> 
    <h1>Ember select view</h1> 

    {{#linkTo 'authors'}}Authors{{/linkTo}} 

    {{outlet}} 
</script> 

<script type="text/x-handlebars" data-template-name="authors"> 
    {{view Ember.Select contentBinding="App.AuthorsController"}} 
</script> 

CODE-JS:

window.App = Ember.Application.create(); 

App.Router.map(function() { 
    this.resource('authors', { path: "/authors" }); 
}); 

App.AuthorsRoute = Ember.Route.extend({ 
    model: function() { 
    return App.Author.find(); 
    } 
}); 

App.AuthorsController = Ember.ArrayController.extend({}) 


//DATA 

//define model for category 
App.Author = DS.Model.extend({ 
    name: DS.attr('string'), 
    language: DS.attr('string') 
}); 

App.Store = DS.Store.extend({ 
    revision: 12, 
    adapter: 'DS.FixtureAdapter' 
}); 

App.Author.FIXTURES = [ 
{ 
    id: 1, 
    name: 'Luc Verschuren', 
    language: 'German' 
}, 
{ 
    id: 2, 
    name: 'Patrick Burms', 
    language: 'Dutch' 
}, 
{ 
    id: 3, 
    name: 'Jean Demeester', 
    language: 'French' 
} 
]; 

回答

1

嘗試使用的content財產您App.AuthorsController具有數據:

<script type="text/x-handlebars" data-template-name="authors"> 
{{view Ember.Select 
    contentBinding="content" 
    optionLabelPath="content.name"}} 
</script> 

工作jsfiddle

希望它有幫助。

+0

這確實有效!我總是對App.AuthorsController,內容和模型之間的區別感到困惑。非常感謝 ! – cyclomarc

+0

@Marc,很高興我能幫上忙,不要忘記標記答案,如果你願意,所以未來的人會知道它適合你 – intuitivepixel

+0

這確實有效,如果選擇視圖可以基於「內容」。但是,當我還想顯示另一個需要使用其他數據呈現的選擇列表時,該怎麼辦。見http://jsfiddle.net/frvJZ/10/ - 在這個例子中,我也想顯示一個包含所有AuthorTypes(定義爲燈具數據)的選擇視圖。任何幫助將非常感激 ! – cyclomarc

相關問題