PDA

View Full Version : Is hooking under deserialization process in Ext.data.JsonStore possible?



--miCZar--
24 Oct 2010, 7:50 PM
Hi all (my first post here),

Is there any possibility to hook before/after deserialization in Ext.data.JsonStore (or if its taken in Ext.data.HttpProxy) to work with received data? Why? In ASP.NET when calling web service (via Ext.data.HttpProxy in this case) ScriptManager serializes date like this "\/Date(ticks)\/" and after deserialization for example I get "/Date(1198908717056)/" and that causes "some" problems. I would like to hook just before deserialization and decode it for proper format so when the data is deserialized it would go smoothly.

I'm completly new to ExtJS (2 days) so any ideas would be appreciated.

I need dates in the store below decoded correctly.

var store = new Ext.data.JsonStore({
root: 'd.Entities',
totalProperty: 'TotalCount',
idProperty: 'Id',
autoLoad: true,
fields: [
{ name: 'Id', type: 'int' }, 'From', 'Subject', 'Body', 'Sent'
],
proxy: new Ext.data.HttpProxy({
url: 'Services.asmx/GetMessages',
headers: { 'Content-type': 'application/json' }
})
});

evant
24 Oct 2010, 8:34 PM
You could use a convert method:

http://dev.sencha.com/deploy/touch/docs/?class=Ext.data.Field&member=convert

--miCZar--
25 Oct 2010, 5:22 AM
Thanks, that's exactly what I was looking for.

EDIT:

So it all should look like this:

var store = new Ext.data.JsonStore({
root: 'd.Entities',
totalProperty: 'TotalCount',
idProperty: 'Id',
autoLoad: true,
fields: [
{ name: 'Id', type: 'int' }, 'From', 'Subject', 'Body', { name: 'Sent', convert: dateTimeConverter }
],
proxy: new Ext.data.HttpProxy({
url: 'Services.asmx/GetMessages',
headers: { 'Content-type': 'application/json' }
})
});

function dateTimeConverter(value, record) {
var deserializedDateTime = value.replace(/\/Date/g, 'new Date').replace(/\//g, '');
return Ext.util.JSON.decode(deserializedDateTime);
}