1

我正在构建一个 Sencha Touch 应用程序,并在登录后努力重定向或更改另一个视图。登录后我需要把它带到主页。但是我在登录控制器的 authenticateUser() 中的以下代码不起作用

也尝试过 Ext.Viewport.push(homePanel) , Ext.Viewport.setActiveItem(homePanel) 。但没有任何效果。

登录视图

Ext.define("Mobile.view.LoginView", {
extend: "Ext.form.FormPanel",
alias: "widget.mylogin",
id: 'loginFormPanel',

config: {


    name: 'loginform',
    frame: true,
    url: 'login/Authenticate',
    title: 'Login',
    items: [

      {
          xtype: 'fieldset',
          itemId: 'LoginFieldset',
          margin: '10 auto 0 auto ',
          title: '',
          items: [

                {
                    //User Name field def
                },

                {
                    //Pwd Field Def
                }
            ]
      },
        {
            xtype: 'button',
            id: 'loginButton',           
            text: 'Login',
            action: 'login'
        }

    ]
}

});

登录控制器

Ext.define("Mobile.controller.LoginController", {
extend: "Ext.app.Controller",
views: ['LoginView', 'HomeView'],
models: ['UserModel'],
config: {
    refs: {
        loginForm: "#loginFormPanel"
    },
    control: {
        'button[action=login]': {
            tap: "authenticateUser"
        }
    }
},

authenticateUser: function (button) {
            loginForm.submit({
            method: 'POST',
            success: function (form, result) {
            //THIS IS NOT WORKING
                Ext.Viewport.add(Ext.create('Mobile.view.HomeView'));

            },
            failure: function (form, result) {                   
                console.log('Error');
                Ext.Msg.alert('Check the logic for login and redirect');
            }
        });
       }           
});

主页视图

Ext.define('Mobile.view.HomeView', {
extend: 'Ext.Container',
id: 'homescreen',
alias: "widget.homepanel",
 config: {
    layout: {
        type: 'card',
        animation: {
            type: 'flip'
        }
    },
    items: [
        {
            xtype: 'toolbar',
            docked: 'bottom',
            id: 'Toolbar',
            title: 'My App',
            items: [
                {
                    id: 'settingsBtn',
                    xtype: 'button',
                    iconCls: 'settings',
                    ui: 'plain',
                    iconMask: true
                }
            ]
        },
        {
            xclass: 'Mobile.view.ActionListView'
        }
    ]
},
});

应用程序.JS

Ext.application({
name: "Mobile",
controllers: ["LoginController", "HomeController"],
views: ['LoginView', 'HomeView', 'ActionListView'],
models: ['UserModel', 'OrganizationModel', 'ActionModel'],
stores: ['OrganizationStore', 'ActionStore'],
launch: function () {

    var loginPanel = Ext.create('Ext.Panel', {
        layout: 'fit',
        items: [
            {
                xtype: 'mylogin'
            }
        ]
    });
    Ext.Viewport.add(loginPanel);
}

});

有人知道吗?已经提到使用 sencha touch 2.0 登录后加载另一个视图。但是没有答案。请帮忙

4

3 回答 3

6

您需要为 HomeView 创建一个 ref:

    refs: {
        HomeView: {
            autoCreate: true,
            selector: 'HomeView',
            xtype: 'HomeView'
        },
    }

并将此视图设置为活动状态:

    Ext.Viewport.setActiveItem(this.getHomeView());
于 2012-10-09T23:18:58.490 回答
1

如果你使用 Sencha Touch 2,你应该使用 Route 重定向到另一个页面。所以,它会是这样的:

this.redirectTo('home');

然后创建一个具有路由“home”的控制器

有关路线的更多信息。http://docs.sencha.com/touch/2-0/#!/guide/controllers-section-4

于 2012-10-11T10:49:37.960 回答
0

试试这个。可能是这个作品。

authenticateUser: function (button) {
        loginForm.submit({
        method: 'POST',
        success: function (form, result) {

         var home= Ext.create('Mobile.view.HomeView');
         Ext.getCmp('loginFormPanel').destroy();
         Ext.Viewport.add(paneltab);

        }
于 2012-10-09T13:41:46.130 回答