2013-08-01 186 views
1

Sencha新手,我有一個很好的登錄表單,並通過ajax按需要發佈表單元素。 onSuccess,它將數據存儲在localStorage.token中,然後移至下一頁。我想要的是,當應用程序加載時,如果localStorage.token中已經有數據,那麼它直接進入第二頁。我嘗試setActiveItem,但沒有得到所需的結果。Sencha Touch活動項目

這裏是我的app.js:

//<debug> 
Ext.Loader.setPath({ 
    'Ext': 'touch/src' 
}); 
//</debug> 

Ext.application({ 
    name: 'axis3', 
    //profiles: ['Phone', 'Tablet', 'Desktop'], 


    requires: [ 
     'Ext.MessageBox' 
    ], 

    views: ['Login','Main'], 
    controllers:['Login','Main'], 

    icon: { 
     '57': 'resources/icons/Icon.png', 
     '72': 'resources/icons/Icon~ipad.png', 
     '114': 'resources/icons/[email protected]', 
     '144': 'resources/icons/[email protected]' 
    }, 

    isIconPrecomposed: true, 

    startupImage: { 
     '320x460': 'resources/startup/320x460.jpg', 
     '640x920': 'resources/startup/640x920.png', 
     '768x1004': 'resources/startup/768x1004.png', 
     '748x1024': 'resources/startup/748x1024.png', 
     '1536x2008': 'resources/startup/1536x2008.png', 
     '1496x2048': 'resources/startup/1496x2048.png' 
    }, 

    launch: function() { 
     // Destroy the #appLoadingIndicator element 
     Ext.fly('appLoadingIndicator').destroy(); 
     // Initialize the login view 
     Ext.Viewport.add([ 
      { xtype: 'loginview' }, 
      { xtype: 'mainview' } 
     ]); 
     Ext.Ajax.setUseDefaultXhrHeader(false);// needed to enable cross domain request. 
    }, 

    onUpdated: function() { 
     Ext.Msg.confirm(
      "Application Update", 
      "This application has just successfully been updated to the latest version. Reload now?", 
      function(buttonId) { 
       if (buttonId === 'yes') { 
        window.location.reload(); 
       } 
      } 
     ); 
    } 
}); 

感謝您的任何援助

回答

1

我想補充一個觀點,即你需要,根據您的令牌檢查的結果:

launch: function() { 
    // Destroy the #appLoadingIndicator element 
    Ext.fly('appLoadingIndicator').destroy(); 

    var hasToken = this.hasToken(); 
    if (hasToken) 
     Ext.Viewport.setActiveItem({ xtype: 'mainview' }); 
    else 
     Ext.Viewport.setActiveItem({ xtype: 'loginview' }); 

    Ext.Ajax.setUseDefaultXhrHeader(false);// needed to enable cross domain request. 
}, 
+0

按需要工作。謝謝Kev。 –