【发布时间】:2017-10-28 23:28:04
【问题描述】:
嗯,我需要在 ajax 请求完成后加载我的模型。
当 ajax 请求完成后,我将数据推送到存储中。推送后,我需要返回数据并将其呈现在模板上。问题是,{{model}} 变量是空的。
model(params) {
const controller = this.controllerFor('users.profile');
return controller.get('session').authorize('authorizer:devise', (headerName, headerValue) => {
const 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);
//at this point I can see the user info in the ember 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);
}
});
});
}
任何建议,我的路线有什么问题?
【问题讨论】:
-
应该是
success: function(data) { .... }? -
我认为你不应该将授权和模型放在一个模型挂钩中。我的建议是:使用 Ember Simple Auth 进行授权!
标签: javascript ajax ember.js model