问题描述
我有一个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);
那么,如何获取价值?
谢谢
推荐答案
好的。经过一些调整后发现答案。为了后代,这里是解决方案:
Ok. Found the answer after some tweaking. For the sake of future generations - here is the solution:
我已经添加了 id:'loginform'
LoginForm然后在控件中的'refs'部分我添加了$ code 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 - 如何获取表单值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!