PDA

View Full Version : Problem with extjs.data.store



dragon001
31 Jul 2010, 3:09 PM
Hi,
I'm having a problem that I couldn't solve till now.

I have a DataStore that get's Information from a Json Container.

Here's the Construct:


function returnDstore(url,colums,id,root,init){
var store = new Ext.data.Store({
url: url,
reader: new Ext.data.JsonReader({
root: root,
id: id
},
colums),
});
if(init == true){
store.load();
}
return store;
}
It worls perfectly for creating Grids.
My Problem now is, that I want to access the data inside the storage.
I need one of it's values.


If I send the storage Object to the Consul I get following Information:

Object
baseParams: Object
batchCounter: 0
batches: Object
data: Object
allowFunctions: false
events: Object
getKey: function (o){
items: Array (25)
0: Object
data: Object
id: "User ID"
json: Object
store: Object
__proto__: Object
1: Object
2: Object
3: Object
4: Object
5: Object

Everything is OK, all Informations are there.
But if I use:
store.getCount it just teels me: 0
If I use
store.getAt(1) and send it to the consule I get undefined.
I don't have a clue, where I went totally wrong.
I hope some body can help me.

chris

Screamy
31 Jul 2010, 5:39 PM
First off, you have an erroneous trailing comma right after "columns" in your datastore config.

Secondly, try this and see if you get data:


function returnDstore(url,colums,id,root,init){
var store = new Ext.data.Store({
url: url,
listeners: {
load: function(store, records, options) {
Ext.Msg.alert("Display Data", "Store record[0] value is " + records[0].get('yourColumnNameHere'));
}
},
reader: new Ext.data.JsonReader({
root: root,
id: id
},
colums)
});
if(init == true){
store.load();
}
return store;
}

And lastly, maybe consider using an Ext.data.JsonStore instead?

fay
1 Aug 2010, 4:03 AM
load() is asynchronous so you need to wait for the store to be "loaded" before using getCount or getAt. Read the Ext.data.JsonStore API docs for the load method:



Important: loading is asynchronous! This call will return before the new data has been loaded. To perform any post-processing where information from the load call is required, specify the callback function to be called, or use a a 'load' event handler.