[英]Sencha Touch 2 - How to get form values?
I've got a Sencha Touch 2 MVC app with a form as a view. 我有一个Sencha Touch 2 MVC应用程序,其中包含一个表单作为视图。 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. 我正在发布我的视图/控制器代码。
View: 视图:
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'
}
]
}
});
And the controller: 和控制器:
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");
}
});
The code will go up to 代码将达到
console.log("onSubmitLogin");
And then stop. 然后停下来。
On launch I use this: 在发布时我使用这个:
var LoginForm = Ext.create("MyApp.view.LoginForm");
Ext.Viewport.add(LoginForm);
So, how can I get the values? 那么,我怎样才能获得价值?
Thanks 谢谢
Ok. 好。 Found the answer after some tweaking. 经过一些调整后找到了答案。 For the sake of future generations - here is the solution: 为了后代 - 这是解决方案:
I've added id:'loginform'
to the LoginForm and then, in the controller in the 'refs' part I've added loginForm: '#loginform'
. 我已经在LoginForm中添加了id:'loginform'
,然后在'refs'部分的控制器中添加了loginForm: '#loginform'
。 Then I could use it as : 然后我可以用它作为:
var values = this.getLoginForm().getValues();
Good luck to all 祝你们好运
Try this 尝试这个
Controller: 控制器:
Ext.define("mySIMS.controller.LoginForm", { extend : "Ext.app.Controller", config : { refs : { btnSubmitLogin : "#btnSubmitLogin", LoginForm : '#loginform' }, control : { btnSubmitLogin : { tap : "onSubmitLogin" } } }, onSubmitLogin : function() { console.log("onSubmitLogin"); var values = this.getLoginForm().getValues(); console.log(values); //var values = Oreilly.views.LoginForm.loginform.getValues(); }, launch : function() { this.callParent(); console.log("LoginForm launch"); }, init : function() { this.callParent(); console.log("LoginForm init"); } });
View: 视图:
Ext.define('mySIMS.view.LoginForm', { extend : 'Ext.form.Panel', config : { id : 'loginform', fullscreen : true, items : [{ xtype : 'fieldset', title : 'Login', items : [{ xtype : 'emailfield', name : 'email', label : 'Email' }, { xtype : 'passwordfield', name : 'password', label : 'Password' }] }, { xtype : 'button', width : '8%', text : 'Login', ui : 'confirm', id : 'btnSubmitLogin' }, { xtype : 'toolbar', docked : 'top', title : 'Mobile' }] } });
Hope this help. 希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.