ExtJs操作Cookie

來源:互聯網
上載者:User

ExtJs操作Cookie

ExtJs操作Cookie方法很簡單,只有三個方法:

clear(name):清除為name設定的值。

set(name,value):設定name的值為value。

get(name):得到為name設定的值。

下面看一個具體樣本:

Ext.onReady(function() {var stringtest = "這是一個字串";var obj = {name : "this is name",description : "this id description"};Ext.util.Cookies.set("test1", stringtest);Ext.util.Cookies.set("test2", Ext.encode(obj));Ext.Msg.alert("提示", "第一個參數:" + Ext.util.Cookies.get("test1")+ " \n第二個參數字串格式:" + Ext.util.Cookies.get("test2")+ " \n擷取第二個字串name屬性值:"+ Ext.decode(Ext.util.Cookies.get("test2")).name);});
這裡需要注意的是,Cookie只能儲存字串,不能儲存物件,如果需要儲存物件,就需要先用Ext.encode()方法將複雜的對象結構轉換為字串,但是在取出該字串的時候需要使用Ext.decode()就可以將字串轉換為原來的物件類型。如果對象中還包含對象,那麼使用encode時會調用內部對象的toString()方法,儲存起來的類型就是“object object”不會儲存類型資料,而調用decode方法時將對象轉換回來時也是字串,而不是原來的對象。

上述樣本運行結果如下:



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.