Sencha Touch Active Item

时间:2013-08-01 15:20:50

标签: sencha-touch-2

Sencha的新手,我有一个运行良好的登录表单,并根据需要通过ajax发布表单元素。 onSuccess,它将数据存储在localStorage.token中,然后移动到下一页。我想要的是,当应用程序加载时,如果localStorage.token中已有数据,那么它将直接进入第二页。我尝试了setActiveItem,但是没有达到预期的结果。

这是我的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/Icon@2x.png',
        '144': 'resources/icons/Icon~ipad@2x.png'
    },

    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 个答案:

答案 0 :(得分: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.
},