Load another view after login with sencha touch 2.0

半城伤御伤魂 提交于 2019-12-04 21:20:12
alamaby

Could you post your app.js too? I'm trying your code here and it load the view as expected. Here is my app.js:

Ext.application({
    name: 'MyApp',

    requires: [
        'Ext.MessageBox'
    ],
    controllers: ['Login'],
    views: ['LoginForm','MainTabPanel'],

    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 main view
        //Ext.Viewport.add(Ext.create('MyApp.view.Main'));
        Ext.Viewport.add(Ext.create('MyApp.view.LoginForm'));
    },

    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();
                }
            }
        );
    }
});

Destroy the login panel, You don't really need it anymore...

success: function(response) {
        var json = Ext.decode(response.responseText);

        if (json.type == 'success') {
            // LOAD THE DAMN SECOND VIEW HERE!
            var paneltab = Ext.create('MyApp.view.MainTabPanel');
            Ext.getCmp('loginForm').destroy();
            Ext.Viewport.add(paneltab);

        } else {
            alert(json.value);
        }
    },

There are several problems here:

  • Your autoCreate rule uses an xtype: 'tabpanel' which will only ever create a vanilla Ext.TabPanel with no items in it. You'd need to assign an xtype attribute to your MyApp.view.MainTabPanel like xtype: 'mainTabPanel' and then use that xtype value in your autoCreate rule.

  • This then explains why this code won't work since this.getMainTabPanel() will return the wrong object. Simpler would be to just use Ext.Viewport.setActiveItem(paneltab).

    • In general, you usually don't want assign an id to a view (id: 'mainTabPanel'). Safer to just use an xtype to fetch it. Although you don't need it in this case, avoiding global id's allows you to create multiple instances of a view (or any other class type).
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!