0

我试图拥有它,以便一旦用户登录并单击刷新,他们将保持在同一页面上。但是现在,当用户登录并单击刷新时,它们会被发送回登录屏幕。我知道在浏览器未关闭时使用会话存储,这是我需要的。我似乎无法让它正常工作。

模型

             Ext.define('MeterReadingsApp.model.Login', {
             extend: 'Ext.data.Model',
              config: {

            fields: [{name: "username", type:'string'}, {name: "password",                                     
               type:'string'}],

                     identifier: 'uuid'

              }
             });    

店铺

  Ext.define('MeterReadingsApp.store.Login', {
                 extend: 'Ext.data.Store',
                        //requires: ['Ext.data.proxy.SessionStorag'],
                         config: {
                    model: 'MeterReadingsApp.model.Login',

                         //sessionStorage.type: 
                proxy: {
                //use sessionstorage if need to save data for that
              //specific session only
           type: 'sessionstorage',
                  id  : 'Login'
            },
                 autoLoad: false
                   }
           });
        //var Login = Ext.create('MeterReadingsApp.store.Login');
            //Login.load();

应用程序.js

launch: function() {
    // Destroy the #appLoadingIndicator element
    Ext.fly('appLoadingIndicator').destroy();
    var session=Ext.getStore('Login');
   session.load();
   var  record = session.getAt('userName');
   alert(record);
   if(record != undefined){
       //exits to main menus not login
   }
   else
        Ext.Viewport.add(Ext.create('MeterReadingsApp.view.Login'));



},

控制器

  loginButton: function(){
// var me = this;

  Ext.Ajax.request({   
           useDefaultXhrHeader:false,
           url: getLogonUrl(),
           method: 'POST',
           headers: { 'Content-Type' : 'application/x-www-form-urlencoded' },
           params : {
           "userName": Ext.getCmp('username').getValue(),
           "password": Ext.getCmp('password').getValue()
           },


           success: function (response) {
               Ext.getCmp('failLogin').hide(),

             Ext.getStore('Login').sync();


               Ext.Viewport.setActiveItem({xtype: 'Main'});
               Ext.getStore('Campuses').load();


           },
           failure: function(response) {
              Ext.getCmp('loginform').doSetHeight(250),
              Ext.getCmp('failLogin').show();

           }
        });
     },

谢谢您的帮助!

4

1 回答 1

0

You need to set the storeId property on the store. You are trying to use the proxy's id to get the store.

于 2014-07-07T23:11:02.703 回答