PDA

View Full Version : Struggling with Store events



mabutt
11 Feb 2011, 11:43 AM
I'm trying to get a callback once my store has retrieved data from the server, but I'm not having any luck. I'm new to ExtJS so have no doubt I'm doing something wrong, but can't see where. The service is being called and returning valid data but my callback function is never firing,

I've tried this, but the callback function never fires.



Ext.onReady(function() {
var siteDataStore = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
method: "GET",
url: "Service.asmx/GetSiteData"
}),

listeners: {
load: function() { alert("loaded"); },
},

autoLoad: true
});
});


I've also tried this:



Ext.onReady(function() {


var siteDataStore = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
method: "GET",
url: "Service.asmx/GetSiteData"
}),
});

siteDataStore.on("load", function() { alert("loaded"); } );
siteDataStore.load();
});


Am I doing something obviously wrong?

ryanyoungsma
11 Feb 2011, 12:28 PM
I am not 100% positive on this, but might you need to explicitly define a reader with this? Meaning you are using Ext.data.Store versus Ext.data.JsonStore.

johnathanhebert
11 Feb 2011, 12:59 PM
Yes, you need to define a DataReader for your store... either JsonReader or XmlReader

arthurakay
11 Feb 2011, 1:04 PM
I would simply use the JsonStore() or XMLStore() objects, rather than define your own reader. Let the framework manage it for you!

If you were to create an event listener for "exception", you'd get a more detailed error message as to WHY your "load" event isn't firing.

johnathanhebert
11 Feb 2011, 1:10 PM
Right... you can pass in any JsonReader config options to the JsonStore constructor and it will create the reader for you with those config options... see the note on the JsonStore API doc:

*Note: Although not listed here, this class accepts all of the configuration options of JsonReader (http://dev.sencha.com/deploy/dev/docs/output/Ext.data.JsonReader.html).