mardi 6 octobre 2015

From list user to user show on ember

I have my list of users in a template, and a show of a user on a different template. It was working no problem. No api call was made when showing user info because data were already loaded when doing the users call. But know on the user show I have user info and user's list of devices that I do with an api call at users/:user_id/devices. I get the proper result only when I refresh the user show page. When I go from the list of user to the user show the data is not loaded in the view. I can see the user list datas in the ember inspector. I’m using an RSVP to load both resources like this :

export default Ember.Route.extend({
  model(params) {
    return Ember.RSVP.hash({
      user: this.store.findRecord('user', params.user_id),
      devices: this.store.query('device', { user: params.user_id })
    });
  }
});

My router is like :

Router.map(function() {
    this.route('users', { path: 'front/users' });
    this.route('user',  { path: 'front/users/:user_id'});
});

In my user template I show user info with {{model.user.first_name}}

Do you think it's possible to keep the data already loaded from the index and make a new api call when going into user show to get the devices?




Aucun commentaire:

Enregistrer un commentaire