PDA

View Full Version : Not sure how data.store works



n00bster
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
})

account_data.load();
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
,"faxPodOption":0,"viewID":3,"openTime":"08:00","closeTime":"17:30","closeLunch":0,"oeShowFuel":0,"oeShowRate"
:0}]}
Shipper is in there as you can see


the alert shows 0
and getAt is undefined.

any tips ?

Condor
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.

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

n00bster
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 :(

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

n00bster
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.

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

n00bster
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.

MD
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.

MD