有空值的EXTJS商店问题 - useNull:没有影响 - 帮助?

时间:2010-11-01 17:25:36

标签: combobox extjs jsonstore

民间,

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

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

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

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

谢谢!

(gah!stoopid声望< 10所以我无法直接发布图片。请在此处查看:debug pic

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

  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 个答案:

答案 0 :(得分:3)

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

{
    name: "primaryIncidentTypeId", 
    convert: function(value, row) {
        return (value == null) ? null : parseInt(value);
    }
}

答案 1 :(得分:0)

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

defaults: {
    anchor: '100%'
}

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

是否可以从服务器端提供转换功能以及所有其他元数据?

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

答案 2 :(得分: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;
};

答案 3 :(得分:-1)

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

示例:

{name:"primaryIncidentTypeId", type:"int", useNull:true , defaultValue: null },