1

如何正确设置控制器的型号?

这是我的代码(出现错误):

<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 修订版 11

提琴手

4

1 回答 1

4

这里有一个关于这个的讨论,但是到目前为止,Ember 控制器使用别名contentfor model,所以你setupController应该是:

App.ApplicationRoute = Ember.Route.extend({
  setupController: function() {
    this.controllerFor('topic').set('content', App.Topic.find());
  }
});

此外,您可以查看使用FixtureAdapter. 请记住,这是一项正在进行的工作,我会在找到时间时对其进行更新。

http://jsfiddle.net/schawaska/KjWKw/

于 2013-02-15T18:39:09.060 回答