使用sencha touch 2.0登录后加载另一个视图 [英] Load another view after login with sencha touch 2.0

查看:172
本文介绍了使用sencha touch 2.0登录后加载另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个愚蠢的问题,我希望你给我一个手。谢谢提前。

I'm having a dumb problem and I would like you to give me a hand.Thanks in advance.

情况如下:我有2个视图(都用sencha architect 2.0创建),一个用于登录,另一个用于一般目的。而当我尝试登录时,我想加载成功响应的第二个视图,这是在任何成功的登录后。主要的问题是我试过Exc.reate,Ext.Viewport.add,Ext.Viewport.setActiveItem,但是我无法使第二个视图出现在屏幕上,登录屏幕只是保持在那里app没有加载其他视图。另一件事,我不必为此使用导航视图。

The situatios is as follows: I have 2 wiews (both created with sencha architect 2.0), one for login, and another for general purposes. And I would like to load the second view on successful response when trying to log in, this is, after any successful login. The main problem is that I've tried with Ex.create, Ext.Viewport.add, Ext.Viewport.setActiveItem, but I can't manage to make the second view to appear on screen, the login screen just keeps there and the app does not load the other view. Another thing, I don't have to use a navigation view for this.

这是我的控制器的代码,我想从中加载我的第二个视图。正如你所看到的,我甚至创建了一个视图引用,它启用了autoCreate,并具有该IDmainTabPanel:

Here is the code of my controller, from which I want to load my second view. And as you'll see, I even created a reference of the view, which has autoCreate enabled and has that ID "mainTabPanel":

Ext.define('MyApp.controller.Login', {
extend: 'Ext.app.Controller',
config: {
    refs: {
        loginButton: {
            selector: '#login',
            xtype: 'button'
        },
        username: {
            selector: '#user',
            xtype: 'textfield'
        },
        password: {
            selector: '#pass',
            xtype: 'passwordfield'
        },
        mainTabPanel: {
            selector: '#mainTabPanel',
            xtype: 'tabpanel',
            autoCreate: true
        }
    },

    control: {
        "loginButton": {
            tap: 'onLoginButtonTap'
        }
    }
},

onLoginButtonTap: function(button, e, options) {
    Ext.Ajax.request({
        url: '../../backend/auth.php',

        method: 'POST',

        params: {
            user: this.getUsername().getValue(),
            pass: this.getPassword().getValue()
        },

        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.Viewport.add(paneltab);
                //Ext.Viewport.setActiveItem(this.getMainTabPanel());
            } else {
                alert(json.value);
            }
        },

        failure: function(response) {
            alert('The request failed!');
        }
    });
}
});

这里是我的登录视图的代码:

And here is the code of my login view:

Ext.define('MyApp.view.LoginForm', {
extend: 'Ext.form.Panel',

config: {
    id: 'loginForm',
    ui: 'light',
    items: [
        {
            xtype: 'fieldset',
            ui: 'light',
            title: 'Log into the system',
            items: [
                {
                    xtype: 'textfield',
                    id: 'user',
                    label: 'User',
                    name: 'user'
                },
                {
                    xtype: 'passwordfield',
                    id: 'pass',
                    label: 'Pass',
                    name: 'pass'
                }
            ]
        },
        {
            xtype: 'button',
            id: 'login',
            ui: 'confirm',
            text: 'Login'
        }
    ]
}
});

最后,我想加载视图的代码。如果将其设置为初始视图,则此视图正常加载,但在成功登录时不会加载:

And finally, the code of the view I want to load. This view loads normally if I set it as the Initial View, but does not load when a successful login occurs:

Ext.define('MyApp.view.MainTabPanel', {
extend: 'Ext.tab.Panel',

config: {
    id: 'mainTabPanel',
    layout: {
        animation: 'slide',
        type: 'card'
    },
    items: [
        {
            xtype: 'container',
            layout: {
                type: 'vbox'
            },
            title: 'Tab 1',
            iconCls: 'time',
            items: [
                {
                    xtype: 'titlebar',
                    docked: 'top',
                    title: 'General Report',
                    items: [
                        {
                            xtype: 'button',
                            iconCls: 'refresh',
                            iconMask: true,
                            text: '',
                            align: 'right'
                        }
                    ]
                },
                {
                    xtype: 'container',
                    height: 138,
                    flex: 1,
                    items: [
                        {
                            xtype: 'datepickerfield',
                            label: 'From',
                            placeHolder: 'mm/dd/yyyy'
                        },
                        {
                            xtype: 'datepickerfield',
                            label: 'To',
                            placeHolder: 'mm/dd/yyyy'
                        },
                        {
                            xtype: 'numberfield',
                            label: 'Hours'
                        }
                    ]
                },
                {
                    xtype: 'dataview',
                    ui: 'dark',
                    itemTpl: [
                        '<div style="height:50px; background-color: white; margin-bottom: 1px;">',
                        '    <span style="color: #0000FF">{user}</span>',
                        '    <span>{description}</span>',
                        '</div>'
                    ],
                    store: 'hoursStore',
                    flex: 1
                }
            ]
        },
        {
            xtype: 'container',
            title: 'Tab 2',
            iconCls: 'maps'
        },
        {
            xtype: 'container',
            title: 'Tab 3',
            iconCls: 'favorites'
        }
    ],
    tabBar: {
        docked: 'bottom'
    }
}
});

请,我需要帮助... :)
我现在被困在这里3天,不知道问题是什么,谢谢。

Please, I need help... :) I'm stuck here for like 3 days now and can't figure out what the problem is. Thank you.

推荐答案

您可以发布您的app.js吗?
我在这里想你的代码,并预期其加载的看法。这是我的app.js:

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

这篇关于使用sencha touch 2.0登录后加载另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆