PDA

View Full Version : Ext.data.Store reader format



cavalleydude
28 Jun 2010, 7:39 AM
Hello, I'm trying to understand how to properly format the JSONReader for my Ext.data.Store object.
I cannot figure out how to format or prototype the Store record. No matter what I do, the Firebug debugger always shows an error "Record.prototype is undefined".

Any help would be greatly appreciated. See my sample code below:

this.store = new Ext.data.Store({
//
// USE proxy to modify request properties
//
proxy: new Ext.data.HttpProxy({
headers: {'Authorization':Ext.util.Cookies.get('auth'),
'Accept':'application/json'},
scope:this,
disableCaching:false,
url:'/myapp/rest/testdata',
method : 'GET'
}),

/*
Returns this JSON data structure. I'm interested in the data-array content.

{"test-data":{"data-array":[
{"code":"8-SW","description":"8-SW"},
{"code":"GLB2","description":"GI-310"},
{"code":"HYT-CD","description":"HYT-E33"},
{"code":"7-NE","description":"7-NE"}
],"totalcount":4}}
*/
reader: new Ext.data.JsonReader({
root: 'test-data',
totalProperty: 'totalcount',
id: 'data-array'
},
{name:'mytestdata', mapping: 'test-data'},
{name:'data', mapping: 'mytestdata.data-array'},
[
{name: 'code', mapping: 'data.code'},
{name: 'description', mapping: 'data.description'}
]
),

...

fay
28 Jun 2010, 8:59 AM
For a start, use a JsonStore (http://www.sencha.com/deploy/dev/docs/?class=Ext.data.JsonStore). Take a look at the \examples\grid-filtering\grid-filtering-local.js (and grid-filter.json) files for an example of what to do.

Remove the "test-data" property name and try this:



{
"data-array":[
{"code":"8-SW","description":"8-SW"},
{"code":"GLB2","description":"GI-310"},
{"code":"HYT-CD","description":"HYT-E33"},
{"code":"7-NE","description":"7-NE"}
],
"totalcount":4
}

// ...

this.store = new Ext.data.JsonStore({
url:'/myapp/rest/testdata',
// ... Additional config options as needed.
root: 'data-array',
idProperty: 'code',
totalProperty: 'totalcount',
fields:[ { name: 'code' }, { name: 'description' } ]
});


P.S. Always use CODE tags when posting.

cavalleydude
28 Jun 2010, 10:18 AM
Thanks Fay

I was trying not to change the server side code as it's used by another application... it looks like that is my only hope. I understand how to make the basic JSON format work, it's just the nested format that I currently have is no good for ExtJS. I'll change the server to make it work.

Thanks
cavalleydude