0
我是nodejs的新手,並且在回調中掙扎。我有一個回調塊,期望從一個子函數的值,但是,我無法理解爲什麼該值不會返回到父塊 - user.getUser。幫助將不勝感激。無法獲取回調函數以將值返回父函數
子功能
getUser(userEmail) {
logger.info('fetching details for user '+userEmail)
dynamoModel.get(userEmail, function(err, userModel){
if(err) logger.error(err);
logger.info(userModel);
return userModel;
});
}
回調
user.getUser(email, function(err, userModel){
logger.info('parent block->'+userModel);
});
輸出
info: fetching details for user dhdhd
info: email=dhdhd, password=ttjtkt, lastLogin=1498963442595, loginVendor=local, createdAt=Sun Jul 02 2017 12:44:02 GMT+1000 (AEST), updatedAt=Sun Jul 02 2017 12:44:02 GMT+1000 (AEST)
info: fetching details for user dhdhd
另外,我不知道爲什麼到的getUser函數的調用是發生多occations - 如從多個日誌條目eveident -
info: fetching details for user dhdhd