samedi 28 octobre 2017

ember - load model from ajax is undefinded

Well, its that, i need to load my model after ajax request complete.

when ajax complete I pushdata into store and after that i need to return these data and render on template but is empty.

model(params)
    {
        const _this = this;

        const controller = this.controllerFor('users.profile');

        return controller.get('session').authorize('authorizer:devise', (headerName, headerValue) => {

                    var url = '/api/users/profile/'+this.get('session.data.authenticated.user.id');

                    return Ember.$.ajax({
                            method: 'GET',
                            url: controller.get('backendURL')+url,
                            dataType: 'json',
                            //data: ,
                            contentType: 'application/json',
                            beforeSend:  function(xhr) {
                                xhr.setRequestHeader(headerName, headerValue);
                            },
                            success: function(

                                _this.store.pushPayload('user',data);

                                //in this point i view ther user info in emebr inspector addon.


                                return Ember.RSVP.resolve(data);//return usr;

                            },
                            error: function(data){
                                controller.get('flashMessages').danger('ERROR, '+ data);
                                Ember.$("#loading").hide("slow");
                                controller.set('seeTable',false);
                            }
                    });
        });

Any suggestions, whats is wrong on my route?




Aucun commentaire:

Enregistrer un commentaire