简体   繁体   中英

Ember.js cannot set content of ArrayController

Suppose I have an ArrayController :

CellarRails.SearchController = Ember.ArrayController.extend({
  content: []
});

and a SearchRoute :

CellarRails.SearchRoute = Ember.Route.extend({
  model: function(params) {
    console.log('MODEL HOOKED!!');
    return CellarRails.Track.find(params);
  }
});

and a find method in model:

CellarRails.Track.reopenClass({
  find: function(params) {
    ...
    some code
    ...
    return result;
  }
});

PROBLEM: The result array is returning properly, model hook is fired, but content of controller is undefined and it's length is 0, so what am I doing wrong?

You should add the setupController hook and setting the content to the model returned by your find() operation:

CellarRails.SearchRoute = Ember.Route.extend({
  model: function(params) {
    console.log('MODEL HOOKED!!');
    return CellarRails.Track.find(params);
  },
  setupController: function(controller, model) {
    controller.set('content', model);
  }
});

Update, in response to your last comment

See here for a working demo.

Hope it helps.

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