开发者

EXTJS Store issue with Null Values -- useNull: doesn't have an affect --Help?

Folks,

I have a combobox component backed by a JSONStore. The data loaded into the store is returning null for the combobox's value. The value is an int. The JSON decode process is converting the null value into a zero; causing the combobox to fail to render when it attempts to find the开发者_运维问答 pk, zero that doesn't exist in its backing store.

I've found the useNull: config option for data.Field objects, upgraded to 3.3.0 Final and set my int value for the combobox to useNull:true. This isn't having any affect at all, unfortunately. The decoded value is still being changed from null to zero.

Any ideas about how to not set the field to a zero when the data for a JSON field is null?

Here's a pic of what's going on. Notice the data: value is zero, but the JSON value is null.

Thanks!

(gah! stoopid reputation < 10 so I can't directly post the pic. View it here: debug pic )

Also, here's my store's field config:

  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"
    ]


Try using it without type declaration. You may also use convert method:

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


About the combo width: I usually use

defaults: {
    anchor: '100%'
}

in the form declaration and have no problems with widths.

Isnt't it possible to provide convert functions from server side together with all other metadata?

And I'm still using ExtJS 3.2 - no need of any new bugs in the production systems :)


This also got me, you can additionally override the type convert function in Ext.data.Types to allow null values for integer type fields.

Ext.data.Types.INT.convert = function(v){
  v = parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10);
  return isNaN(v) ? null : v;
};


You must use defaultValue: null ,useNull : true because default value for integet type is zero

Example:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜