简体   繁体   中英

Force to get all data in RSVP hash in Ember Cli

Ember Cli doesn't work with relational data (relatesTo and hasMany) the way Ember normally should do. In order to make it work, I use a RSVP hash and set the model in the controller manually.

export default Ember.Route.extend({

  model: function(params) {
    return Em.RSVP.hash({
      traits: this.store.find('trait'),
      person: this.store.find('person', params.person_id)
    });
  },

  setupController: function(controller, model) {
    controller.set('model', model.person);
  }
});

This gets the person with the given ID and his traits. In this case, since the person only has two traits assigned, only those two data objects are returned.

Let's say on this route I want to give the user the ability to change the traits of this person. So, I want to display ALL traits with checkboxes. How in the route above do I force the request to get all the traits, not just two?

I tried store.all(), but that only filters the local data. Since no data is present yet, it return 0 objects.

Ember-cli just helps with setting up your project structure and building it. It doesn't run Ember any different. If you want all of the traits in your template or on your controller you should actually keep track of them after you've fetched them.

export default Ember.Route.extend({

  model: function(params) {
    return Em.RSVP.hash({
      traits: this.store.find('trait'),
      person: this.store.find('person', params.person_id)
    });
  },

  setupController: function(controller, model) {
    controller.set('model', model.person);
    controller.set('allTraits', model.traits);
  }
});

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