在 Sencha Touch 中,如何使用从表单字段收到的输入进行计算?
假设我有一个这样的表单:
var Sum1 = new Ext.form.FormPanel({
id: 'Sum1',
items: [{
xtype: 'fieldset',
title: 'Step 1: Calculating The Sum',
items: [{
xtype: 'numberfield',
name: 'num1',
label: 'First Number'
},{
xtype: 'numberfield',
name: 'num2',
label: 'Second Number'
},{
xtype: 'numberfield',
name: 'num3',
label: 'Third Number'
},{
xtype: 'numberfield',
name: 'num4',
label: 'Fourth Number'
},{
xtype: 'button',
name: 'CalcSum',
ui: 'Confirm',
text: 'Calculate Sum',
handler: function() {
Ext.getCmp('Total').setValue('1');
}
}]
},{
xtype: 'fieldset',
title: 'Calculated Total',
items: [{
xtype: 'textfield',
name: 'Total',
id: 'Total',
placeHolder: 'Your Calculated Total'
}]
});
我想要做的是在某种方法中使用值num1-4
,对它们求和并返回一个值 - 然后在我的文本字段Total中设置该值
。
我对 Sencha Touch 非常陌生,并且正在使用 Sencha Touch 2.0,因此希望得到任何帮助。
谢谢。
Say I have a form like this:
var Sum1 = new Ext.form.FormPanel({
id: 'Sum1',
items: [{
xtype: 'fieldset',
title: 'Step 1: Calculating The Sum',
items: [{
xtype: 'numberfield',
name: 'num1',
label: 'First Number'
},{
xtype: 'numberfield',
name: 'num2',
label: 'Second Number'
},{
xtype: 'numberfield',
name: 'num3',
label: 'Third Number'
},{
xtype: 'numberfield',
name: 'num4',
label: 'Fourth Number'
},{
xtype: 'button',
name: 'CalcSum',
ui: 'Confirm',
text: 'Calculate Sum',
handler: function() {
Ext.getCmp('Total').setValue('1');
}
}]
},{
xtype: 'fieldset',
title: 'Calculated Total',
items: [{
xtype: 'textfield',
name: 'Total',
id: 'Total',
placeHolder: 'Your Calculated Total'
}]
});
What I want to do is to use the values num1-4
in some method that sums them and returns a value - which is then set in my textfield Total
.
I am very new to Sencha Touch, and am using Sencha Touch 2.0, so would love any assistance.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
我会听
blur
方法。此方法将在您的文本字段失去焦点后调用。然后你可以做你的事情并将其吐出在total
字段中吗?请参阅 API:http://docs.sencha.com /touch/2-0/#!/api/Ext.field.Text
也许:
或者(我认为更好)
更新 2012-01-30:
您可以在同一个文件中定义它,甚至可以在每个字段中定义它:
更好的方法是定义一个函数,您可以在同一个文件中执行它;
I would listen to the
blur
method. This method will be called after your textfield loose focus. Then you can do your thing and spit it out in thetotal
field?See API: http://docs.sencha.com/touch/2-0/#!/api/Ext.field.Text
Perhaps:
or (I think better)
UPDATE 2012-01-30:
You can define this in the same file, or even per field:
Better way is to defin one function, you can do it in the same file;