mercredi 3 juin 2015

Loading multiple models on same route returns good json from server but empty model

I want to load multiple models on the same route. Right now, I am doing it using setupController. Basically, I am calling the server to fill up the models for conversations, subusers and currentsubuser.

Subusers returns a json array that is correctly loaded into the store.

The call for currentsubuser returns good json from the server (as shown here : http://ift.tt/1KEldp5), but is not loaded correctly into the store (as shown here : http://ift.tt/1AOb74J) unlike the subusers.

As you can see, I am using the very same code for loading the subusers and currentuser, but I don't know why the datas from currentsubuser can't be loaded into the store.

The models for currentsubuser and subuser are identical, they contain the exact same properties (FYI I tried sideloading the currentsubuser into the same payload as subusers without success so I created its own identical model):

App.Subuser = DS.Model.extend({

name: DS.attr('string'),
email: DS.attr('string'),
conversations: DS.hasMany('conversation'),
openedConvCount: DS.attr('number'),
profileImage: DS.attr('string'),

});

App.Currentsubuser = DS.Model.extend({

name: DS.attr('string'),
email: DS.attr('string'),
conversations: DS.hasMany('conversation'),
openedConvCount: DS.attr('number'),
profileImage: DS.attr('string'),

});

Route :

App.ConversationsRoute = Ember.Route.extend({

subusers: null,
currentsubuser: null,

model: function(params){

        return this.store.find('conversation', { status : params.status});
},

setupController: function(controller, model){

    this._super(controller, model);

    if(!this.get('subusers') && !this.get('currentsubuser'))
    {
        this.set('subusers', this.store.findAll('subuser'));
        this.set('currentsubuser', this.store.find('currentsubuser'));
    }

    this.controllerFor('subusers').set('content', this.get('subuser'));
    this.controllerFor('currentsubuser').set('content', this.get('currentsubuser'));
},

queryParams: {
    status: {
        refreshModel: true
    }
}
});

Router :

App.Router.map(function(){

//Routing list to raw namespace path
this.resource('conversations', { path : '/' }, function() {
    this.resource('conversation', { path : '/:conversation_id'});
});

});




Aucun commentaire:

Enregistrer un commentaire