PDA

View Full Version : Accessing DataStore Record Fields



rehanazher
29 Jul 2009, 10:32 AM
Hi All ,

I think this question must have been posted before but I was unable to find the solution so posting again.
I want to assign my Data.store record row columns to globally accessible variables (within my function).

Below is the response of my HTTP Proxy:

{rows:[{"rackid":"1","rackName":"2259","racktype":"GENERAL RACKS","rackUCount":"42"}]}


And below is my code for my DataStore:



var myResult;
var RackInfo = new Ext.data.Store({
autoDestroy: true,
reader: new Ext.data.JsonReader({
root: 'rows',
id: 'rackid',
fields: [
{name: 'RACKID', mapping: 'rackid',type: 'int'},
{name: 'RACKNAME', mapping: 'rackName'},
{name: 'RACKTYPE', mapping: 'racktype'},
{name: 'UCount', mapping: 'rackUCount',type: 'int'},
]
}),
proxy: new Ext.data.HttpProxy({
url: 'include/getRackInfo.php',
})
});
RackInfo.on("load", function() {
myResult = RackInfo.getAt(0);
alert(myResult.get('RACKNAME')); // I get 2259 which is correct
alert(RackInfo.getCount()); //i get 1 which is correct

});
RackInfo.load({params: {id1: 1}});
alert(myResult.get('RACKNAME')); // I get an Error myResult is undefined
alert(RackInfo.getCount()); //i get 0 which is in correct according to mu understanding

Pllease help me in this regard, what need to be done with some code example as I am newbie to EXT JS.

carol.ext
29 Jul 2009, 11:07 AM
See Grid FAQ (http://extjs.com/learn/Ext_FAQ_Grid#Store_appears_empty_even_after_calling_load.28.29) about Store appearing empty after load call due to asynchronous nature.

rehanazher
29 Jul 2009, 8:28 PM
Hi,

Thanks for the reply,

I have already checked and my question is how can I access DataStore record (members/columns) values outside the Ds.on.

carol.ext
30 Jul 2009, 6:22 AM
You need to change your thinking. You already see how to access the store after it is loaded. What else do you need to do that you cannot?