Sencha Touch 2 - 如何获取表单值? [英] Sencha Touch 2 - How to get form values?

查看:22
本文介绍了Sencha Touch 2 - 如何获取表单值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以表单为视图的 Sencha Touch 2 MVC 应用程序.我试图从控制器获取它的值但没有成功.

I've got a Sencha Touch 2 MVC app with a form as a view. I'm trying to get it's values from the controller with no success.

这是怎么做到的?我正在发布我的视图/控制器代码.

How could this be done? I'm posting my view/controller code for this one.

查看:

Ext.define('MyApp.view.LoginForm', {
    extend: 'Ext.form.Panel',
    config: {
        fullscreen: true,
        items: [
            {
                xtype: 'fieldset',
                title: 'Login',
                id: 'loginform',
                items: [
                    {
                        xtype: 'emailfield',
                        name: 'email',
                        label: 'Email'
                    },
                    {
                        xtype: 'passwordfield',
                        name: 'password',
                        label: 'Password'
                    }
                ]
            },
            {
                xtype: 'button',
                width: '50%',
                text: 'Login',
                ui: 'confirm',
                id: 'btnSubmitLogin'
            },
            {
                xtype: 'toolbar',
                docked: 'top',
                title: 'MyApp Mobile'
            }
        ]
    }
});

和控制器:

Ext.define("MyApp.controller.LoginForm", {
    extend: "Ext.app.Controller",
    config: {
        refs: {
            btnSubmitLogin: "#btnSubmitLogin"
        },
        control: {
            btnSubmitLogin: {
                tap: "onSubmitLogin"
            }
        }
    },
    onSubmitLogin: function () {
        console.log("onSubmitLogin");
        var values = app.views.LoginForm.loginform.getValues();
        TryLogin(values['email'], values['password']);
    },
    launch: function () {
        this.callParent();
        console.log("LoginForm launch");
    },
    init: function () {
        this.callParent();
        console.log("LoginForm init");
    }
});

代码将上升到

console.log("onSubmitLogin");

然后停下来.

在启动时我使用这个:

var LoginForm = Ext.create("MyApp.view.LoginForm");
Ext.Viewport.add(LoginForm);

那么,我如何获得这些值?

So, how can I get the values?

谢谢

推荐答案

好的.经过一些调整后找到了答案.为了子孙后代 - 这是解决方案:

Ok. Found the answer after some tweaking. For the sake of future generations - here is the solution:

我已将 id:'loginform' 添加到 LoginForm 中,然后在控制器的 'refs' 部分中添加了 loginForm: '#loginform'.然后我可以将它用作:

I've added id:'loginform' to the LoginForm and then, in the controller in the 'refs' part I've added loginForm: '#loginform'. Then I could use it as :

var values = this.getLoginForm().getValues();

祝大家好运

这篇关于Sencha Touch 2 - 如何获取表单值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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