7

伙计们,

我有一个由 JSONStore 支持的组合框组件。加载到存储中的数据为组合框的值返回 null。该值是一个 int。JSON解码过程是将空值转换为零;导致组合框在尝试查找 pk 时无法呈现,零在其后备存储中不存在。

我找到了 data.Field 对象的 useNull: config 选项,升级到 3.3.0 Final 并将我的组合框的 int 值设置为 useNull:true。不幸的是,这根本没有任何影响。解码后的值仍在从 null 更改为零。

当 JSON 字段的数据为空时,关于如何不将字段设置为零的任何想法?

这是正在发生的事情的照片。注意数据:值为零,但 JSON 值为空。

谢谢!

(啊!stoopid 声誉 < 10 所以我不能直接发布图片。在此处查看: 调试图片

另外,这是我商店的字段配置:

  fields: [
        {name:"id", type:"int"},
        {name:"occurenceDate", dateFormat: 'Y-m-d\\TH:i:s', type:"date"},
        {name:"docketNumber", type:"string"},
        {name:"courtLocationId", type:"int", useNull:true},
        {name:"assignedOfficerId", type:"int", useNull:true},
        {name:"primaryIncidentTypeId", type:"int", useNull:true},
        {name:"secondaryIncidentTypeId", type:"int", useNull:true},
        {name:"tertiaryIncidentTypeId", type:"int", useNull:true},
        {name:"incidentLocation", type:"string"},
        {name:"summary", type:"string"},
        {name:"personalItemsSeized", type:"string"},
        "supplements",
        "parties",
        "judgeIds"
    ]
4

4 回答 4

3

尝试在没有类型声明的情况下使用它。您也可以使用转换方法:

{
    name: "primaryIncidentTypeId", 
    convert: function(value, row) {
        return (value == null) ? null : parseInt(value);
    }
}
于 2010-11-02T10:54:57.120 回答
0

关于组合宽度:我通常使用

defaults: {
    anchor: '100%'
}

在表单声明中并且宽度没有问题。

难道不能从服务器端与所有其他元数据一起提供转换功能吗?

而且我仍在使用 ExtJS 3.2 - 生产系统中不需要任何新错误 :)

于 2010-11-04T04:44:19.927 回答
0

这也让我明白了,您还可以覆盖 Ext.data.Types 中的类型转换函数以允许整数类型字段的空值。

Ext.data.Types.INT.convert = function(v){
  v = parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10);
  return isNaN(v) ? null : v;
};
于 2010-12-17T03:12:10.610 回答
-1

您必须使用defaultValue: null ,useNull : true,因为整数类型的默认值为零

例子:

{name:"primaryIncidentTypeId", type:"int", useNull:true , defaultValue: null },
于 2017-01-25T11:48:58.237 回答