解决回调地狱的问题
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;
}
网友评论