o2oa api: wait | o2oa开发平台-游戏厅捕鱼达人

module

this.wait是一个方法,可以用来处理异步调用时的页面加载。
该方法使用的具体场景:为了加快速度,需要一次性加载全部外部资源(如:数据字典、外部js、内容管理文档等)后,再进行表单的加载。
this.wait需和this.goon配合使用。
目前只有流程表单的queryload事件支持此方法。

usable range

process

syntax

var resolve = this.wait(); //让表单停止加载页面
if (resolve && resolve.cb){
     resolve.cb(); //通过 resolve.cb() 方法继续执行表单加载
}else{
     //如果没有发生异步,则resolve.cb方法不存在,
     //所以在回调中中使用this.goon();使表单继续加载
     this.goon();
}

example

需要在加载数据字典,内容管理文档数据,按照条件获取的脚本后,再进行加载表单。

var resolve = this.wait(); //this.wait()让表单加载等待回调
var scriptloaded = false; //脚本是否加载完成标识,按条件判断的脚本才建议用this.include(),否则使用预加载脚本更快。
var documentloaded = false; //内容管理文档是否加载完成标识
var dictloaded = true; //数据字典是否加载完成标识
//检查是否全部资源已加载,如果是继续加载表单
var checkload = function(){
    if (scriptloaded && documentloaded && dictloaded){ //各种资源以及加载完成
      if (resolve && resolve.cb){
           resolve.cb(); //通过 resolve.cb() 方法继续执行表单加载
       }else{
           //如果没有发生异步,则resolve.cb方法不存在,
           //所以在回调中中使用this.goon();使表单继续加载
           this.goon();
       }
     }
}.bind(this);
//判断内容管理文档加载
if( this.data.documentid ){
     //异步载入内容管理文档
     o2.actions.get("x_cms_assemble_control").getdocument(this.data.documentid, function (json) {
         this.form.documentjson = json; //将数据存在this.form上,以便其他地方使用
         documentloaded = true; //标记内容管理加载完成
         checkload(); //检查全部资源是否完成加载
     }.bind(this), null, true); //true 为异步加载标志
 }else{
    documentloaded = true; ////标记内容管理加载完成
    checkload(); //检查全部资源是否完成加载
}
//判断脚本加载
if( this.data.scriptname ){ //假设scriptname为判断条件
     //加载脚本
    this.include( this.data.scriptname, function(){  //第二个参数为异步加载后的回调
        scriptloaded = true; //标记脚本加载完成
        checkload(); //检查全部资源是否完成加载
    }, true ); //第三个参数表示异步
}else{
     scriptloaded = true; ////标记脚本加载完成
    checkload(); //检查全部资源是否完成加载
}
//加载数据字典bulletindictionary的category数据
var dict = new dict("bulletindictionary");
dict.get("category", function(data){ //成功的回调
         this.form.bulletincategory = data; //将数据存在this.form上,以便其他地方使用
         dictloaded = true; //标记数据字典加载完成
         checkload(); //检查全部资源是否完成加载
   }.bind(this), function(xhr){ //错误的回调
         dictloaded = true; ////标记数据字典加载完成
         checkload(); //检查全部资源是否完成加载
   }, true //异步执行
)

source

网站地图