我在if
function
内拨打callback
node
。 function
会启动并完成其任务,但我无法弄清楚如何从function
中检索response
。
callback
foo() {
merchant.createCustomerProfile(cardNumber, expDate, email, id, function callback(){
// How do I retrieve the response from the callback?
// console.log(callback);
});
//so I can pass it out here and use it
}
function
实际为callback
returns
。它看起来像这样,
callback
我正在尝试获取应该在回调函数响应中的function createCustomerProfile(cardNumber, expDate, email, id, callback) {
ctrl.execute(function(){
var apiResponse = ctrl.getResponse();
var response = new ApiContracts.CreateCustomerProfileResponse(apiResponse);
if(response != null)
{
if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK)
{
console.log('Successfully created a customer profile with id: ' + response.getCustomerProfileId());
}
else
{
console.log('Result Code: ' + response.getMessages().getResultCode());
console.log('Error Code: ' + response.getMessages().getMessage()[0].getCode());
console.log('Error message: ' + response.getMessages().getMessage()[0].getText());
}
}
else
{
console.log('Null response received');
}
callback(response);
});
}
。
答案 0 :(得分:1)
你可以尝试这个:
foo() {
merchant.createCustomerProfile(cardNumber, expDate, email, id, function callback(response){
// How do I retrieve the response from the callback?
// console.log(callback);
console.log(response);
});
//so I can pass it out here and use it
}