【问题标题】:ExtJS 5.1 Remember Me on local storeExtJS 5.1 在本地商店记住我
【发布时间】:2016-12-01 00:23:45
【问题描述】:

我正在尝试用一个有趣的算法来记住我。我在想,当我单击记住我并登录时,文本字段(用户名和密码)的值将保存为默认值。我的登录按钮点击事件在这里:

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

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

【问题讨论】:

    标签: javascript extjs


    【解决方案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.
    

    【讨论】:

    • 你也可以使用本地存储。
    【解决方案2】:

    在你看来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');
    }
    

    【讨论】:

      猜你喜欢
      • 2015-02-06
      • 1970-01-01
      • 2020-03-02
      • 2011-12-24
      • 2012-12-21
      • 2017-02-24
      • 2012-10-01
      • 2014-03-11
      • 2014-01-21
      相关资源
      最近更新 更多