【发布时间】:2011-05-17 11:00:47
【问题描述】:
全部,
我在尝试使用 Extjs 的 JSONStore 通过 POST 创建新记录时遇到强制转换异常。当将空字符串传递给服务器并且服务器尝试将其转换为整数时,会发生异常。组合框的 valueField 设置为 int 定义的字段。数据存储字段如下:
fields: [
{ name: 'id', type: 'int' },
{ name: 'displayOrder', mapping: 'displayOrder', type: 'int' },
{ name: 'displayName', mapping: 'displayName', type: 'string' },
{ name: 'enabled', mapping: 'enabled', type: 'boolean' },
{ name: 'letterCode', mapping: 'letterCode', type: 'string' }
],
组合框定义为:
{
xtype: 'combo',
id:"secondaryIncidentCombo",
hiddenName: 'secondaryIncidentTypeId',
forceSelection: true,
width:"200",
selectOnFocus: true,
emptyText: 'Secondary Incident',
editable: false,
mode: 'local',
displayField: 'displayName',
valueField: 'id',
store: this.secondaryIncidentTypeArrayStore,
triggerAction: 'all'
},
奇怪的是,用于发送 POST 的 JSONStore 将组合框的值作为空字符串发送,即使我已将 JSONWriter 配置为不发送未更改的字段:
writer: new Ext.data.JsonWriter({
encode: false,
writeAllFields:false
}),
以及发送到服务器的POST值:....,"secondaryIncidentTypeId":"",...
这里是secondaryIncidentTypeArrayStore:
secondaryIncidentTypeArrayStore: new Ext.data.ArrayStore({
idProperty: 'id',
fields: [
{ name: 'id', mapping: 'id', type: 'int' },
{ name: 'displayOrder', mapping: 'displayOrder', type: 'int' },
{ name: 'displayName', mapping: 'displayName', type: 'string' },
{ name: 'enabled', mapping: 'enabled', type: 'boolean' },
{ name: 'letterCode', mapping: 'letterCode', type: 'string' }
],
data: []
})
我即将手动检查空字符串,如果字符串为空,则将其设置为 null。这看起来很笨拙。在表单提交时向服务器发送任何内容或空值的正确方法是什么?
谢谢!
【问题讨论】: