当我在xhr.then()中返回“结果”并且使用dojo 1.10.4时,我遇到了一些问题!
以下代码通过dojo中的xhr('dojo / request / xhr')连接到API:
remandFlow: function(postData, flowId) {
return xhr(this.REMAND_URL + flowId, {
method: 'POST',
data: postData,
handleAs: 'json',
headers: {'X-CSRFToken': cookie("csrftoken")}
}).then(
lang.hitch(this, function(result){
return result;
}),
lang.hitch(this, function(error){
return error;
})
);
},
下面的代码获取以上代码的结果:
editStepUser: function(stepComponent, routeComponent) {
this.model.remandFlow(postData).then(
function(result){
console.log(result) //I can not get it, It's undefined
result.targeted_step_id = postData.route_step_id;
},
function(result){
result.targeted_step_id = postData.route_step_id;
}
);
},
因此,在第二个代码中,我无法获得结果,结果为“未定义”。请帮助我,我是新手道场。
谢谢!!
最佳答案
如果这样测试会怎样?
remandFlow: function(postData, flowId) {
// edit : added console.log
console.log('remandFlow : ' , postData , '|' , flowId);
console.log('remandFlow => this.REMAND_URL : ' , this.REMAND_URL);
return xhr(this.REMAND_URL + flowId, {
method: 'POST',
data: postData,
handleAs: 'json',
headers: {'X-CSRFToken': cookie("csrftoken")}
}).then(
function( result ){ return result; } ,
function( error ){ return error; }
/*
lang.hitch(this, function(result){
return result;
}),
lang.hitch(this, function(error){
return error;
})
*/
);
},