[英]Add values in a form Sencha Touch 2
我有几个FormPanel。 您可以在每个值中输入值。 我需要一些东西来添加所有这些值。 我可以使用循环或函数吗? 这是我的代码:
view1.js:
Ext.define('myApp.view.fp2', {
extend: 'Ext.form.Panel',
alias: 'widget.fp2',
config: {
id: 'fp2',
styleHtmlContent: true,
items: [
{
xtype: 'fieldset',
styleHtmlContent: true,
title: 'Prueba 3',
items: [
{
xtype: 'selectfield',
docked: 'bottom',
id: 'f3',
margin: 10,
labelWidth: '0%',
autoSelect: false,
options: [
{
text: '0',
value: 0
},
{
text: '1',
value: 1
}
]
}
]
},
{
xtype: 'fieldset',
styleHtmlContent: true,
title: 'Prueba 4',
items: [
{
xtype: 'selectfield',
docked: 'bottom',
id: 'f4',
margin: 10,
labelWidth: '0%',
autoSelect: false,
options: [
{
text: '0',
value: 0
},
{
text: '1',
value: 1
},
{
text: '2',
value: 2
}
]
}
]
},
{
xtype: 'fieldset',
styleHtmlContent: true,
title: 'Prueba 5',
items: [
{
xtype: 'selectfield',
docked: 'bottom',
id: 'f5',
margin: 10,
labelWidth: '0%',
autoSelect: false,
options: [
{
text: '0',
value: 0
},
{
text: '1',
value: 1
},
{
text: '2',
value: 2
},
{
text: '3',
value: 3
}
]
}
]
},
{
xtype: 'fieldset',
html: 'pregunta 6',
styleHtmlContent: true,
title: 'Prueba 6',
items: [
{
xtype: 'selectfield',
docked: 'bottom',
id: 'f6',
margin: 10,
labelWidth: '0%',
autoSelect: false,
options: [
{
text: '0',
value: 0
},
{
text: '1',
value: 1
}
]
}
]
}
{
xtype: 'button',
docked: 'bottom',
itemId: 'button2',
margin: 10,
ui: 'forward',
text: 'siguiente'
//go to view2.js
}
]
}
});
view2.js与view1类似,但具有其他值。 汇总所有值的最佳方法是什么?
提前致谢。
合计? 我认为您想将它们全部作为键值来获取?
对于每个Ext.form.FormPanel
调用
var valueObj = formRef.getForm().getValues();
如果现在要将它们合并为一个对象,则可以
Ext.apply(sumValueObj, valueObj ); // will override already existing props
要么
Ext.applyIf(sumValueObj, valueObj ); // will not override already existing props
您可以使用一个函数来求和所有需要的值,并且可以通过所有选择字段的change事件触发该函数。
在控制器中,您可以像这样监听更改事件:
'fp2 selectfield' : {
change : 'onDataChange'
},
在onDataChange
方法中,您可以执行以下操作:
var values = Ext.getCmp("fp2").getValues();
// code to add/subtract whatever you want
附注:我尚未测试此代码,所以请忽略错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.