2014-09-01 42 views
0

當用戶註銷時,我想要移除所有面板,特別是登錄頁面後面的主要條目,即「Main.js」及其子視圖,如「我的數據」你在下面看到,原因是我想確保正確的商店數據將被加載,而不是顯示舊數據。Sencha Touch:登出時銷燬面板

但是,我不確定如何執行此操作以及在用戶註銷時卸載存儲/刪除視圖的最佳做法。

處理用戶註銷的最佳做法是什麼?

Main.js

Ext.define('app.view.Main', { 

extend: 'Ext.tab.Panel', 

xtype: 'main', 

requires: [ 
    'app.view.TeacherPanel', 
    'app.view.ParentPanel', 
    'app.view.AboutPanel', 
    'app.view.user.Profile' 
], 

config: { 

    tabBarPosition: 'bottom', 

}, 

initialize: function() { 

    console.log('main.initialize'); 

    this.callParent(arguments); 

    // add data panel 
    var dataPanel = { 
     title: 'My Data', 
     iconCls: 'home', 
     xtype: eMaliApp.services.App.getActivePanel() 
     store: 'somestore' // i want this to be reloaded 
    }; 
    this.add(dataPanel); 

    // add user panel 
    var profilePanel = { 
     title: 'Profile', 
     iconCls: 'user', 
     xtype: 'userprofile' 
    }; 
    this.add(profilePanel); 

    // add about panel 
    var aboutPanel = { 
     title: 'About', 
     iconCls: 'info', 
     xtype: 'aboutpanel' 
    }; 
    this.add(aboutPanel); 

    // Load general app data 
    app.services.Store.loadSomeStores(); 
} 

});

Profile.js

onLogoutTap: function(e) { 
    Ext.Ajax.request({ 
     url: 'session/mobileLogout', 
     method: 'POST', 
     useDefaultXhrHeader: false, 
     withCredentials: true, 
     callback: function(options, success, response) { 
      if (!success) { 
       console.log('Logout failed, redirecting to login page anyway'); 
      } 
      //Ext.getCmp('main').destroy(); // should be so 
      Ext.Viewport.removeAll(true, true); // does not remove main 
      Ext.Viewport.add(Ext.create('app.view.LoginPanel')); 
     } 
    }); 
} 

回答

1

通常我銷燬停用

Ext.define('App.controller.View', { 
extend: 'Ext.app.Controller', 

config: { 
    refs: { 
     view: '.whatever your view is comes here. Take a look at autocreate.' 
    }, 
    control: { 
     view: { 
      deactivate: 'onViewDeactivate' 
     } 
    } 
}, 

onViewDeactivate: function (view) { 
    Ext.defer(function() { 
     view.destroy(); 
    }, 500); 
}, 

這所有的意見會破壞當前視圖,500毫秒後(時間花費在動畫)。好東西有一個地方,你做這個雖然。

但是,回到你的例子:

var items = Ext.Viewport.getItems(); 

現在遍歷所有項目並摧毀他們。