View 注销更改视图sencha touch

View 注销更改视图sencha touch,view,login,sencha-touch-2,logout,View,Login,Sencha Touch 2,Logout,嗨,我需要在我的sencha touch应用程序中实现保持登录 请参阅下面我的代码: Login.js-一旦用户单击Login,它将在本地存储中存储“sessionToken”。然后它将转到主页 onBtnLoginClick: function(){ var loginviewGetValue = Ext.getCmp('loginview').getValues(); var bbid = Ext.getCmp('bbID').ge

嗨,我需要在我的sencha touch应用程序中实现保持登录

请参阅下面我的代码:

Login.js-一旦用户单击Login,它将在本地存储中存储“sessionToken”。然后它将转到主页

   onBtnLoginClick: function(){

            var loginviewGetValue =  Ext.getCmp('loginview').getValues();
            var bbid =  Ext.getCmp('bbID').getValue();
            var bbpassword =  Ext.getCmp('bbPassword').getValue();
                var LoginLS =   Ext.getStore('LoginLS');





                                    LoginLS.add({
                                        sessionId: 'sadsadsadasd'
                                       ,deviceId:'1'
                                       ,bb_id :bbid
                                       });

                                       LoginLS.sync();      

                                   var mainForm= Ext.create('bluebutton.view.Main');
                                    Ext.Viewport.setActiveItem(mainForm);
        launch: function() {




        // Destroy the #appLoadingIndicator element
        Ext.fly('appLoadingIndicator').destroy();


        // Initialize the main view

             var LoginLS = Ext.getStore('LoginLS');
             LoginLS.load();

             var record =  LoginLS.getAt(0);


            if(record != undefined){
                var sessionId = record.get('sessionId');
               if (sessionId !=undefined){
                     Ext.Viewport.add(Ext.create('bluebutton.view.Main'));
               }
               else
                   Ext.Viewport.add(Ext.create('bluebutton.view.Login'));

            }
            else{
               Ext.Viewport.add(Ext.create('bluebutton.view.Login'));
               }

//        Ext.create('bluebutton.view.TopMenuList');

    },
App.js~每次启动函数都会检查localStorage中的sessionToken。如果Localstorage为空,则它将转到登录页。否则它将转到主页

   onBtnLoginClick: function(){

            var loginviewGetValue =  Ext.getCmp('loginview').getValues();
            var bbid =  Ext.getCmp('bbID').getValue();
            var bbpassword =  Ext.getCmp('bbPassword').getValue();
                var LoginLS =   Ext.getStore('LoginLS');





                                    LoginLS.add({
                                        sessionId: 'sadsadsadasd'
                                       ,deviceId:'1'
                                       ,bb_id :bbid
                                       });

                                       LoginLS.sync();      

                                   var mainForm= Ext.create('bluebutton.view.Main');
                                    Ext.Viewport.setActiveItem(mainForm);
        launch: function() {




        // Destroy the #appLoadingIndicator element
        Ext.fly('appLoadingIndicator').destroy();


        // Initialize the main view

             var LoginLS = Ext.getStore('LoginLS');
             LoginLS.load();

             var record =  LoginLS.getAt(0);


            if(record != undefined){
                var sessionId = record.get('sessionId');
               if (sessionId !=undefined){
                     Ext.Viewport.add(Ext.create('bluebutton.view.Main'));
               }
               else
                   Ext.Viewport.add(Ext.create('bluebutton.view.Login'));

            }
            else{
               Ext.Viewport.add(Ext.create('bluebutton.view.Login'));
               }

//        Ext.create('bluebutton.view.TopMenuList');

    },
Logout.js~注销将清除sessionToken并再次进入登录页面

onLogoutClick: function scan() {
                var LoginLS = Ext.getStore('LoginLS');


                     Ext.Viewport.setMasked({
                        xtype: 'loadmask',
                        message: 'Loading...'
                    });



                 LoginLS.load();

                 var record =  LoginLS.getAt(0);
                   LoginLS.removeAll();
                    LoginLS.sync();
                   //Load a new view


//                   Ext.getCmp('tabpanel').destroy();






                var loginForm = Ext.create('bluebutton.view.Login');
                Ext.Viewport.setActiveItem(loginForm);   

                Ext.Viewport.setMasked(false); // hide the load screen
但我现在有个问题。我无法返回登录页面。它转到空白页。请给我一些解决办法。谢谢

这是我得到的错误

    [WARN][Ext.data.Batch#runOperation] Your identifier generation strategy for the model does not ensure unique id's. Please use the UUID strategy, or implement your own identifier strategy with the flag isUnique. Console.js:35
[WARN][Ext.Component#constructor] Registering a component with a id (`loginview`) which has already been used. Please ensure the existing component has been destroyed (`Ext.Component#destroy()`. Console.js:35
[WARN][Ext.Component#constructor] Registering a component with a id (`bbID`) which has already been used. Please ensure the existing component has been destroyed (`Ext.Component#destroy()`. Console.js:35
[WARN][Ext.Component#constructor] Registering a component with a id (`bbPassword`) which has already been used. Please ensure the existing component has been destroyed (`Ext.Component#destroy()`. Console.js:35
[WARN][Ext.Component#constructor] Registering a component with a id (`btnLogin`) which has already been used. Please ensure the existing component has been destroyed (`Ext.Component#destroy()`. Console.js:35
[DEPRECATE][bluebutton.view.Login#show] Call show() on a component that doesn't currently belong to any container. Please add it to the the Viewport first, i.e: Ext.Viewport.add(component); 

对组件使用
itemId
,而不是
id
,并在
Controller
中相应地引用它们。检查此问题:

查看错误消息,很明显您正在尝试再次创建登录面板,而不销毁现有组件。出现错误是因为不允许您在应用程序中多次使用相同的
id

为了避免这种情况,您不应该多次创建同一个视图,您应该重用视图,这对性能也有好处。还有一件事,您应该给n元素
id
,当且仅当您不能没有它时

假设无法避免
id
属性,则应执行以下两项操作之一:

  • 仅当新视图不存在时创建新视图

    var loginView = Ext.getCmp("loginview");
    if(!loginView){
        loginView = Ext.create('bluebutton.view.Login');
    }
    
  • 通过调用以下命令,在登录视图离开(隐藏/删除)视口后立即销毁该视图:

    var loginView = Ext.getCmp("loginview");
    loginView.destroy();
    

  • 你得到的错误是什么>嗨,我更新了我的问题。你是什么意思?我不明白。很抱歉,我是新来的sencha touchCool Floyd,第二个对我来说更有价值!