简体   繁体   中英

Ember RSVP Hash not updating controller content

I am trying to have handle multiple controllers at one route in Ember. This response seems like the way to go, but am having difficult getting this to work. Here is a simple example that fails to work:

App.IndexRoute = Ember.Route.extend({
  model: function() {
    myData = [1,2,3];

    return Em.RSVP.hash({
      docs1: myData,
      docs2: myData
    });    
  },
  setupController: function(controller, model) {
    controller.set('model', model.docs1);    
    this.controllerFor('documents').set('model', model.docs2);
  }
});

App.DocumentsController = Ember.ArrayController.extend({
  count: function() {
    return this.get('length');
  }.property('@each'),  
});

App.IndexController = Em.ArrayController.extend({  
  count: function() {
    return this.get('length');
  }.property('@each'),  
});

And a JSBin showing the results:

http://jsbin.com/wavigada/1/edit

You can see that the IndexController reports the correct count of 3, but the DocumentsController doesn't get set.

Can anyone help me out?

You will need to include the documents controller whose content you populate in setupController in your IndexController via needs :

App.IndexController = Em.ArrayController.extend({  
  needs: ['documents'],
  count: function() {
    return this.get('length');
  }.property('@each'),  
});

Then you need to change your template to:

<script type="text/x-handlebars" data-template-name="index">
  {{count}}
  {{render 'documents' controllers.documents}}
</script>

Note that just putting {{render 'documents' controllers.documents}} (as you did in your question) refers to a documents property of your current model, which doesn't exists.

See: http://jsbin.com/wavigada/6/

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