2023年5月19日 星期五

V20302 –Cookie – 如何判斷後端資料已更新完成, 才出現子畫面 -2 - settrue , waittrue - Cookie

 目的: V20302 – [確認除帳] – 如何判斷後端資料已更新完成, 才出現子畫面 -2 
           利用 myfunc.js 的  settrue , waittrue  - 設定Cookie 欄位值 & 取得Cookie欄位

處理說明: 1>當 store.on('load' 時, settrue(par_key) - 設定Cookie 為 true
                  2>waittrue(par_key, AddItem) - 直到 Cookie 為 true 時,才執行函式

1>*.js
    Ext.getCmp('sub1_Grid2').store.getProxy().url = '../api/V20302BAPI/getsubData2';
    Ext.getCmp('sub1_Grid2').store.getProxy().extraParams = np; //分頁OK,篩選條件OK    
    Ext.getCmp('sub1_Grid2').store.load();           
    
    //將 CSM_AF@TLS_245 的專案承辦人(以@分隔人員編號) 加入 副本.人員 [姓名][Notes_Email]
    Ext.getCmp('sub1_Grid2').store.on('load', function (me, records, successful, operation, eOpts) {        
        settrue("sub1_Grid2");
    }
    );

    waittrue("sub1_Grid2", AddItem);
    function AddItem() {
        Add_sub1_Grid2(par_EMPLYIDnot6);        
        Ext.getCmp('sub1_Grid2').getView().refresh();
    }
    



2>myfunc.js  -->   settrue()    waittrue()
/*
//函式名稱 : settrue  
傳入參數: par_key: string
設定 Cookie(par_key) 為 true 時
 */
function settrue(par_key, call_func) {
    Ext.util.Cookies.set(par_key,true);
}

/*
//函式名稱 : waittrue  
   傳入參數 : par_key : string
   若 Cookie(par_key) 為 true 時,才執行函式 call_func
*/
function waittrue(par_key, call_func) {
    console.log("par_key:", par_key);
    var timer = setInterval(function () {
        //var Tmp_loaded = decodeURIComponent(Ext.util.Cookies.get(par_key));
        var Tmp_loaded = Ext.util.Cookies.get(par_key);
        if (Tmp_loaded) {
            Ext.util.Cookies.clear(par_key);
            clearInterval(timer);  //不再重覆執行
            call_func();
            return;
        }
    }, 1000);
    };       // end ot waittrue()
    

沒有留言:

張貼留言