我对 jQuery 1.9.1 Promise 有疑问,我可能需要条件逻辑来返回另一个 deferred,但我不知道如何处理它。这是我最好的尝试,但正如下面的评论所示,当我点击 else 分支时,我仍然点击了第二个 .then() 函数,我希望我可以回到用户那里。如何处理这种情况的任何模式?
storage.provision(c)
.then(function(rc){
if(rc === 0){
storage.write(c);
}else{
return options.onSuccess(rc); //how i got back to the users callbacks/promise, but this
//takes me to the .then below
}
})
//storage.write returns a promise as well, do I do another .then
// like this?
.then(function(rc){
//I was hoping this would catch, the storage.write() case, and it does, but it also catches
//the retun options.onSuccess(rc) in the else case.
options.onSuccess(rc);
})
.fail(function(e){
//handle error using .reject()
});