2013-08-01 120 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。 –