使用$.when实现异步调用的链式写法
作者:
蘇上方 | 来源:发表于
2017-04-25 15:00 被阅读24次
解决回调地狱的问题
this.actionId = queryParam('actionId');
$.when(this.isActive())
.done(() => { //成功执行的函数体
window.getToken = this.getToken;
window.getImei = this.getImei;
this.initEvent();
this.initActInfo();
})
.fail( ()=> {
androidJs.doAndroidAction("toastError",JSON.stringify({toastString: '当前活动已关闭'})) //失败执行的函数体
});
isActive(){
let dtd = $.Deferred();
$.ajax('/action/check?actionId='+this.actionId+'').then( (res) => {
if(res.value)
dtd.resolve(); #返回Deferred状态
else
dtd.reject();
})
return dtd;
}
本文标题:使用$.when实现异步调用的链式写法
本文链接:https://www.haomeiwen.com/subject/dduvzttx.html
网友评论