2016-07-27 65 views
1

我正在嘗試記住我一個有趣的算法。我在想,當我點擊記住我和登錄時,文本字段的值(用戶名&密碼)將被保存爲默認值。我的登錄按鈕點擊事件在這裏:ExtJS 5.1記住我在本地商店

var username = Ext.getCmp('setNo').getValue(); 
    var password= Ext.getCmp('setPass').getValue(); 

    if(refs.checkStudent.value === true){ 
     Ext.getCmp('setNo').setValue(username); 
     Ext.getCmp('setPass').setValue(password); 
    } 
    else{ 
     Ext.getCmp('setNo').setValue(""); 
     Ext.getCmp('setParola').setValue(""); 
    } 

控制檯上,這是工作。但我正在與本地商店合作,沒有服務器。所以當我刷新頁面時,它已經消失了。有沒有辦法不輸掉他們?

回答

1

你的看法onAfterRender事件:

Ext.getCmp('setNo').setValue(localStorage.username); 
Ext.getCmp('setPass').setValue(localStorage.password); 

在您的按鈕單擊事件:

if (refs.checkStudent.value === true) { 
    localStorage.username = Ext.getCmp('setNo').getValue(); 
    localStorage.password = Ext.getCmp('setPass').getValue(); 
} else { 
    localStorage.removeItem('username'); 
    localStorage.removeItem('password'); 
} 
1
Use ExtJs utility to set and get values in cookies. At time of login set 
username and password in cookies and after refresh the page read username 
and password value from the cookie. 

Ext.util.Cookies.set('username', username); // To set value in cookie. 
Ext.util.Cookies.get('username'); // to get value form cookie. 
+1

你也可以使用本地存儲來做到這一點。 –