View Full Version : Not sure how data.store works

17 Jun 2009, 10:38 AM
I am trying to load up a data.store with data and access the data after.

here is the jacascript I used

account_data = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'DSAccount-getdata.php'}),
root: 'topics',
totalProperty: 'totalCount',
reader: new Ext.data.JsonReader({
{name: 'Shipper',mapping:'Shipper'}
remoteSort: false

alert (account_data.getCount());
alert (account_data.getAt(0).data.Shipper);

the result from the php is :

{"totalCount":"1","topics":["surcharge":"4.900","fueldate":"Jun 14 2009
12:00AM","Shipper":"TEST ACCOUNT","massEnabled":0,"customDBrefNO":null,"readyOff":null,"private":0
Shipper is in there as you can see

the alert shows 0
and getAt is undefined.

any tips ?

17 Jun 2009, 10:41 AM
load() is asynchronous. You have to wait for the load event or the callback before the store is loaded, e.g.

callback: function(){
alert (account_data.getCount());
alert (account_data.getAt(0).data.Shipper);

17 Jun 2009, 11:10 AM
i did that but it is still the same.. there is no records loaded and getAT is undefined.

in the debugger I dont see any data also :(

17 Jun 2009, 3:12 PM
Read the documentation for the JsonReader, look at the config properties you need to pass.

17 Jun 2009, 3:49 PM
Well I got it to work using the method described above, all fine and dandy there.

I read the documentation , but what I am asking is HOW do i access the data.store data AFTER everything is done and loaded up later on in another part of some java script.

17 Jun 2009, 7:07 PM
As Condor said, loading is asynchronous, so once the store fires the load event, it's populated.

17 Jun 2009, 8:54 PM
Yes I understand that.

But my question is again.. HOW to access the data.store information OUTSIDE an event once it already is populated.

17 Jun 2009, 9:16 PM
Huh? You simply refer to the variable/object you initially set for the store; account_data -- and then use any of Ext.data.Store methods (http://extjs.com/deploy/ext-3.0-rc2/docs/#Ext.data.Store-methods) to extract/manipulate the data in whichever way you please.