ExtJS 5.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(""); 
    } 

控制台上,这是工作。但我正在与本地商店合作,没有服务器。所以当我刷新页面时,它已经消失了。有没有办法不输掉他们?

你的看法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'); 
} 

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

你也可以使用本地存储来做到这一点。 –