ExtJs封裝通用函數

通用函數

  • 添加數據到cookie
/**
 * 添加到cookie中數據
 * @param {} name 保存到cookie中的數據的key
 * @param {} value key對應的value
 * @param {} expireDays 有效時間,單位爲天
 * @return {Boolean}
 */ 
function addCookie(name,value,expireDays){
    var cookieString=name+"="+escape(value);
    if(expireDays>0){
           var date=new Date();
           date.setTime(date.getTime()+expireDays*24*3600*1000);
           cookieString=cookieString+"; expires="+date.toGMTString();
    }
    document.cookie=cookieString;
    return true;
}
  • 從cookie中取出數據
/**
 * 從cookie中取出信息
 * @param {} name cookie鍵名稱
 * @return {String}
 */
function getCookie(name){
    var strCookie=document.cookie;
    var arrCookie=strCookie.split("; ");
    for(var i=0;i<arrCookie.length;i++){
          var arr=arrCookie[i].split("=");
          if(arr[0]==name){
              return unescape(arr[1]);
          }
    }
    return "";
}
  • 超時提醒,重新登錄
Ext.Ajax.on('requestcomplete', function(conn,response,options){

    //console.log(response);
    if(response.responseText == "433"){   
         Ext.MessageBox.alert("提示信息","登錄超時,請重新登錄",function(r) {
                    //跳轉回登錄頁面
            window.location.href = basePath + 'main/logon!logout';
        });
    }   
}); 
  • 獲取JSP頁面穿過來的參數值
/**
 * 按照名字接收get請求參數,
 * @param name
 * @returns
 * 耿延龍
 */
function GetQueryString(name)
{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return decodeURI(decodeURI(unescape(r[2]))); return null;
}
  • 加載頁面,但是通過後臺傳遞數據轉發到前臺的參數不能使用
/**
 * 加載頁面
 * @param {} $divId 要渲染的div
 * @param {} $url 請求地址
 */
function loadPageDiv($divId, $url){

    Ext.getCmp($divId).loader = 
    {   url: $url, 
        scripts: true,
        nocache: true,
        renderer : function(loader, response, active) {

              loader.getTarget().update(response.responseText, true);
              return true;
      }     
    };

    Ext.getCmp($divId).getLoader().load();
}
  • 拿到中間div,加載新的頁面,參考頁面:人員考覈選擇類型後,擊下一步進入新頁面
Ext.getCmp('contentCenter').loader = 
{   url: basePath + 'empExamTotal/emp-exam-total!goExamListExt', 
//          form: 'examTypeForm',
    scripts: true,
    nocache: true,
    params: form.getForm().getValues(),
    renderer : function(loader, response, active) {

          loader.getTarget().update(response.responseText, true);
          return true;
    }       
};
Ext.getCmp('contentCenter').getLoader().load();
發佈了110 篇原創文章 · 獲贊 19 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章