ExtJS運用cookie儲存登入資訊

來源:互聯網
上載者:User

項目上有一個這樣的需求:登入的時候選擇一個單位名稱,然後輸入帳號完成登入,下次登入的時候,“單位選擇”框裡自動顯示為上次登入的頁面。
具體實現如下:

            {
   xtype : 'combo',                              //這裡是選擇單位的Combo
   id:'orgname',
   store : orgStore,
   name:'orgname',
   emptyText : '請選擇單位',
   displayField : 'orgname',
   valueField : 'dbname',
   editable : false,
   forceSelection : true,
   triggerAction : 'all',
   shadow : 'frame',
   hiddenName : 'dbname',
   listeners:{
              select:function(){                                                          //增加1個select函數,當選擇的時候,將選擇結果儲存入cookie
                savedbname= Ext.getCmp('orgname').getValue();
                                 Ext.util.Cookies.set('savedbname',savedbname);
   }
     }
  }

 

 
 var orgStore = new Ext.data.JsonStore( {                                 //這是單位選擇Combo的資料來源
  url : 'test/LoginOrgSelectServlet',
  root : 'orgselect',
  fields : [ 'orgname', 'dbname' ],
  autoLoad : true,
  listeners:{load:function(){                                                  //給store添加一個load監聽器
     var cookiedata = Ext.util.Cookies.get("savedbname");
     if (cookiedata!=null){Ext.getCmp('orgname').setValue(cookiedata);}   //當cookie中的資料不為空白的時候,設定combo的值
  }}
 });

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.