[SOLVED] Data not read into a Store using JsonReader
July 4th, 2009
var myRecordObj = Ext.data.Record.create([
{name: 'id'},
{name: 'itemid'},
{name: 'starttime', type: 'date', dateFormat: 'd-M-Y g:ia'},
{name: 'endtime', type: 'date', dateFormat: 'd-M-Y g:ia'},
{name: 'latestendtime', type: 'date', dateFormat: 'd-M-Y g:ia'}
]);
var myReader = new Ext.data.JsonReader({
root: 'data',
totalProperty: 'results',
id: 'id'
}, myRecordObj);
var myDS = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'admin_getItemListing.php',
method: 'POST'
}),
reader: myReader,
listeners: {
load: function(store) {
alert(store.getAt(0).get('id'));
},
loadexception: function(proxy, store, response, e) {
alert(e.message);
}
}
});
myDS.load();
As you can see, I've added a couple of listeners to try to see what's going on.
The Json response from the server is as follows:
{"success":true,"data":{"id":"1","itemid":"1","starttime":"25-Mar-2008 3:14pm","endtime":"27-Mar-2008 12:00am","finished":"f","fixedprice":null,"currentprice":null,"latestendtime":"01-Jan-1970 12:00am"},"results":1}
I can see that the data is being read from the server ok if I run a
alert(Ext.encode(myReader.jsonData));
Firebug produces shows an error message of:
store.getAt(0) has no properties
alert(store.getAt(0).get('id'));
Can anyone help?
the Json response from the server was wrong. should have been:
{"success":true,"data":[{"id":"1","itemid":"1","starttime":"25-Mar-2008 3:14pm","endtime":"27-Mar-2008 12:00am","finished":"f","fixedprice":null,"currentprice":null,"latestendtime":"01-Jan-1970 12:00am"}],"results":1}
ie data is an array
#If you have any other info about this subject , Please add it free.# |