PDA

View Full Version : Bug in Ext.data.JsonReader?



mainmanmauricio
10 Jun 2009, 6:13 AM
Hi,

I am new to Ext-js and I encountered a peculiarity that just might be a bug.

In my Extjs 3.0 RC2 based program, using an Ext.data.ArrayReader to fill a grid works
while using an Ext.data.JsonReader to do the same job gives me
a grid containing only blank lines.

It seems that this is not by chance. Ext.data.ArrayReader is derived from Ext.data.JsonReader and
the only difference is the implementation of the readRecords method.

Closer inspection leads me to suspect the following method in Ext.data.JsonReader.

// private extractValues
extractValues: function(data, items, len) {
var f, values = {};
for(var j = 0; j < len; j++){
f = items[j];
var v = this.ef[j](data); // v is always undefined
values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue, data);
}
return values;
},

The values extracted are from the json data object are always undefined. Probably because
they are extracted by name instead of being extracted by position.

I am doing something foolish or is this a bug?

Thanks.

Kind regards,
Maurice

Animal
10 Jun 2009, 6:18 AM
They are different classes. Using them to do the same job is wrong.

mainmanmauricio
10 Jun 2009, 6:33 AM
They are different classes. Using them to do the same job is wrong.

Sure, the point I was trying to make is that I expected a JsonReader to work to read the JSON
encoded data (which I am returning from the webserver).

But for some reason, the JsonReader does not work but the ArrayReader does.
I guest it is just me.

Kind regards,
Maurice

Animal
10 Jun 2009, 6:49 AM
If you return an Array as each data row object, it will need an ArrayReader

Animal
10 Jun 2009, 6:51 AM
I have proposed a merger whereby JsonReader and ArrayReader become one, and it just uses either numeric indices or string property names: http://extjs.com/forum/showthread.php?t=69453

But no response from the dev team.

mainmanmauricio
10 Jun 2009, 10:40 AM
They are different classes. Using them to do the same job is wrong.


I have proposed a merger whereby JsonReader and ArrayReader become one, and it just uses either numeric indices or string property names: http://extjs.com/forum/showthread.php?t=69453

But no response from the dev team.

Thanks!

I can't imagine why it would be deemed appropriate for a JsonReader class to not properly deal with JSON encoded data.

But then again I do not know Javascript very well and maybe arrays are not objects in Javascript.

Anyway if the JsonReader were to have properly dealt with arrays it would have saved me quite a bit of debugging.

Kind regards,
Maurice

Animal
10 Jun 2009, 11:25 AM
JsonReader reads an object.

It's not JSON once it gets into the browser.

JSON is what is on thw wire.

JSON is a string representation of data.

You are confused here.

mjrobin
22 Nov 2012, 3:35 AM
Im getting the following error on a getForm().submit. My objective is to search on multiple fields and return json stringto store to a grid



TypeError: l.fields is undefined


file:///C:\Users\mark\AppData\Local\Temp\msohtmlclip1\01\clip_image001.gif
...else{l=b._lastItemForPoint;if(l){b.fireEvent("itemmouseout",l);delete b._lastIte...



My json




success
true



results
1



rows
[Object { client_id=
"1"
, clientdate=
"2012-09-15"
, trn=
"1234567"
, more...}, Object { client_id=
"2"
, clientdate=
"1972-09-15"
, trn=
"78899"
, more...}]



0
Object { client_id=
"1"
, clientdate=
"2012-09-15"
, trn=
"1234567"
, more...}



client_id
"1"



clientdate
"2012-09-15"



trn
"1234567"



lname
"name"



fname
"My"



1
Object { client_id=
"2"
, clientdate=
"1972-09-15"
, trn=
"78899"
, more...}



client_id
"2"



clientdate
"1972-09-15"



trn
"78899"



lname
"brown"



fname
"yanique"




Code giving error:


function success_handler(frm, action){
//alert(Ext.encode(action.result));
//var jSource=(Ext.encode(action.result));

var Record = Ext.data.Record.create([ 'trn','firstname','lname' // map the Record's "job" field to the row object's "occupation" key
]);

var myReader = new Ext.data.JsonReader(
{
totalProperty: "results",
root: "rows",
idProperty: "client_id"
},
Record
);


var store = new Ext.data.Store({reader: myReader});
// store.loadData(Ext.util.JSON.decode(jSource));
console.log(store);

Any insight will be appreciated