如何正确设置控制器模型?
这是我的代码(收到错误):
<script>
window.App = Ember.Application.create();
App.Store = DS.Store.extend({
revision: 11,
adapter: 'DS.FixtureAdapter'
});
App.ApplicationRoute = Ember.Route.extend({
setupController: function() {
this.controllerFor('topic').set('model', App.Topic.find());
}
});
App.Topic = DS.Model.extend({
label: DS.attr('string'),
selected: DS.attr('boolean')
});
App.Topic.FIXTURES = [
{ id: 1, label: '1. First topic', selected: true },
{ id: 2, label: '2. Second topic' },
{ id: 3, label: '3. Third topic' },
];
App.TopicController = Ember.ArrayController.extend();
App.IndexController = Ember.ObjectController.extend({
content: [],
test: 'INDEX TEST',
currentTopics: null
});
</script>
模板(尝试将TopicController绑定到Ember.Select视图)
<script type="text/x-handlebars" data-template-name="index">
{{view Ember.Select
contentBinding="App.TopicController"
selectionBinding="currentTopics"
optionLabelPath="content.label"
optionValuePath="content.id"}}
</script>
版本: ember 1.0.0-pre4 ember-data revision 11
答案 0 :(得分:4)
有关此here的讨论正在进行中,但截至目前,Ember控制器对content
使用别名model
,因此您的setupController
应为:
App.ApplicationRoute = Ember.Route.extend({
setupController: function() {
this.controllerFor('topic').set('content', App.Topic.find());
}
});
此外,您还可以查看使用FixtureAdapter
的 this sample fiddle 。请记住,这是一项正在进行的工作,我会在找到时间时更新它。