我试图做承诺链接,但我得到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 –