ExtJS表单getValues转换为int一些值
我有一个带有几个字段的搜索表单(ExtJS 4.2):ExtJS表单getValues转换为int一些值,extjs,extjs4,extjs4.1,extjs4.2,extjs-mvc,Extjs,Extjs4,Extjs4.1,Extjs4.2,Extjs Mvc,我有一个带有几个字段的搜索表单(ExtJS 4.2): xtype: 'fieldcontainer', layout: 'hbox', items: [{ xtype: 'combobox', itemId: 'cboEmployee', width: 400, store: cboEmployeeStore, cls: 'arigth', displayField: 'Fu
xtype: 'fieldcontainer',
layout: 'hbox',
items: [{
xtype: 'combobox',
itemId: 'cboEmployee',
width: 400,
store: cboEmployeeStore,
cls: 'arigth',
displayField: 'FullName',
valueField: 'EmployeeId',
queryMode: 'remote',
fieldLabel: 'Employee',
editable: true,
hideTrigger: true,
queryParam: 'searchStr',
name: 'EmployeeId',
minChars: 3,
listConfig: {
loadingText: 'Searching...',
// Custom rendering template for each item
getInnerTpl: function() {
return '<b>{EmployeeNumber}</b> / {FullName}';
}
}
}, {
xtype: 'datefield',
fieldLabel: 'From',
name: 'FromDate',
format: 'd/m/Y',
submitFormat: 'Y-m-d H:i:s',
width: 180,
labelWidth: 50,
cls: 'arigth',
value: new Date()
}, {
xtype: 'datefield',
fieldLabel: 'To',
name: 'ToDate',
format: 'd/m/Y',
submitFormat: 'Y-m-d H:i:s',
width: 165,
labelWidth: 25,
cls: 'arigth',
value: new Date()
}, {
xtype: 'button',
action: 'search',
text: 'Search',
margin: '0 0 0 20'
}]
我不能这样做:form.getValues()
因为我将EmployeeId=“”
而EmployeeId
必须是整数
这就是我实现每个
语句的原因,但是
当项目为字段集类型时,我会收到一个错误,因为f.getName()
未定义,所以我不知道这是否是在EmployeeId
字段值为“”时设置EmployeeId=0
的最佳方法(空字符串)
如果您需要
EmployeeId
为0(如果它是空字符串),那么在获取所有表单值后只需执行该检查。此外,通过使用表单的getFieldValues
函数,可以将字段值作为其实际类型,而不是全部作为字符串
// this assumes form is the FormPanel
var formValues = form.getForm().getFieldValues();
// check if the EmployeeId value is null/undefined/""
if(!formValues['EmployeeId']) {
formValues['EmployeeId'] = 0;
}
简单但很棒…我不知道getForm().getFieldValues()是的,我在几个月前才发现,在使用Ext两年后。
// this assumes form is the FormPanel
var formValues = form.getForm().getFieldValues();
// check if the EmployeeId value is null/undefined/""
if(!formValues['EmployeeId']) {
formValues['EmployeeId'] = 0;
}