PDA

View Full Version : JsonReader



x5150
3 May 2007, 4:24 PM
I have a grid working using ArrayReader but I can't get the grid to work using JsonReader using,


var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'?gfrm=2'}),
reader: new Ext.data.JsonReader({
root: 'rows',
totalProperty: 'results',
id: 'id'
},
[
{name: 'ID', mapping: 'id', type: 'int'},
{name: 'Name', mapping: 'name', type: 'string'},
{name: 'Color', mapping: 'color', type: 'string'}
]),
// turn on remote sorting
remoteSort: true
});

Where my url is a link to a empty page except for the text output of the object in json format.

# gfrm2 page just contains the json formatted string
{"rows":[{"color":"blue","name":"Tim","id":76},{"color":"aquamarine","name":"Stacie","id":57}],"results":2}

I just get a grid with no rows. What am I doing wrong? Is using the jsonReader going to be any faster or more efficient or just better style than ArrayReader? Thanks.

jsakalos
3 May 2007, 4:30 PM
You use json reader to read data sent from server, array reader for data already in your app.

Using firebug to see what is sent to server and what comes back?

x5150
3 May 2007, 4:31 PM
The json object is created using perl on a server running mod_perl. Here is my code


package xxxxxxxx;
@ISA = qw( xxxxxxx );

sub setDefaults {
my $self = shift;
# return json encoded
use JSON;
my $json = new JSON;
$obj = {results => 2, rows => [ { id => '76', name => 'Tim', color => 'blue'}, { id => '57', name => 'Stacie', color => 'aquamarine'}] };
$js = $json->objToJson($obj);
$datahref->{jsonObj} = $js;
}

tryanDLS
3 May 2007, 4:32 PM
url is a url, not a querystring parm.

x5150
3 May 2007, 4:39 PM
I tried both the full url and just the param. Nothing comes up in the firebug console.

tryanDLS
3 May 2007, 4:50 PM
You need to look at the 'Net' tab in firebug - if you don't see anything, it's because you never sent a request. I don't see a store load in your code. Have you looked at the grid tutorial and/or the example that load from something other than a arrayreader?

x5150
4 May 2007, 9:47 AM
Thanks. I looked at the net tab in firebug and it was not loading because I did not have ds.load() in my code. I also had to comment out 'remoteSort: true'.