我試圖做承諾鏈接,但我得到undefined
爲我的鏈中的一部分,我不確定爲什麼。這個問題似乎是當我使用serviceFactory.GetProjectManager()
。當我回復它時,似乎沒有返回承諾,而是自動進入下一個.then()
,解決的值爲undefined
。承諾鏈接返回undefine
如果GetProjectManager
返回一個字符串,我從函數調用返回它不會包裝它在一個承諾,並傳遞給下一個承諾鏈?
dataFactory.GetProject()
.then(function(result){
return result.Response.ProjectId;
}).then(function(projectId){
return serviceFactory.GetProjectManager(projectId);
})
.then(function(result){
//GET UNDEFINED HERE <---------
})
.catch(function(error){
});
如果我寫類似下面的代碼,那麼它將返回回調正確的價值,但我不希望使用回調我想用扁平承諾鏈接。
dataFactory.GetProject()
.then(function(result){
return result.Response.ProjectId;
}).then(function(projectId){
serviceFactory.GetProjectManager(projectId
,function(result){
//Returns Project Manager Here <----
}
,function(error){
});
})
.catch(function(error){
});
serviceFactory.GetProjectManager是否返回承諾,還是隻接受回調作爲參數? –
它只接受回調,我想這一定是承諾鏈接不起作用的原因? – FillyPajo
好猜@FilipJuristovski –