PDA

View Full Version : Problem reading json data from a store



ivansaracino
29 Apr 2010, 1:06 AM
Hi all,
I'm using ExtJs 3.0.0
I'm trying to read a json response from a serser side resource with such code:





var mystore = new Ext.data.Store( {
proxy : new Ext.data.HttpProxy({ url : 'precarica-ordine'}),

reader : new Ext.data.JsonReader( {
successProperty: 'success',
root : 'dato',
fields :[
'numeroOrdine',
'tipoOrdine'

]

}),

autoLoad : true
});

mystore.on('load', function() {
console.log("data loaded ...")
mystore.each(function(record){
console.log(record.data);
});
});








With firebug I see this json response from the server: {"dato":{"numeroOrdine":"34","tipoOrdine":"desadv"},"success":true}
I see the log "data loaded ..."

but the store has no records :(.
mystore.getCount() return 0.

What 's wrong?

Thx all for the attention
Ivan Saracino

cnelissen
29 Apr 2010, 7:02 AM
dato should be an array of records, not a single object. I.e.:

{"success":true, "dato":[{"numeroOrdine":"34","tipoOrdine":"desadv"}]}

ivansaracino
30 Apr 2010, 1:31 AM
dato should be an array of records, not a single object. I.e.:

{"success":true, "dato":[{"numeroOrdine":"34","tipoOrdine":"desadv"}]}

Thx for your answer.

Now the response is an array or records.

But still I have a loadexception, defining a listener in the JsonStore:



....
listeners: {

loadexception: function(){
console.log(arguments);
}
}
...


I catched this message error message : "Record is undefined" name: "Type error".

any suggestion?
Thanks.
Ivan Sarcino