简体   繁体   中英

Ember js how to set controller's model with DS.FixtureAdapter?

How to set controller's model properly?

Here is my code (getting error):

<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>

Template ( trying to bind TopicController to Ember.Select view )

<script type="text/x-handlebars" data-template-name="index">

  {{view Ember.Select
     contentBinding="App.TopicController"
     selectionBinding="currentTopics"
     optionLabelPath="content.label"
     optionValuePath="content.id"}}

</script>

Versions: ember 1.0.0-pre4 ember-data revision 11

JsFiddle

There's a discussion going on about this here , but as of now, Ember Controllers use the alias content for model , so your setupController should be:

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

Additionally, you can check out this sample fiddle that uses the FixtureAdapter . Just keep in mind this is a work in progress and I'll be updating it as I find time.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM