PDA

View Full Version : xml and Ext.data.Store



fenix94i
29 Apr 2007, 10:33 AM
Hello everybody, :)

I use the class Ext.data.Store which contains "reader: new Ext.data.XmlReader", but how can I know when my AJAX request is over?

I need help please.thanks

fenix94i
29 Apr 2007, 10:51 AM
Hello everybody, :)

I use the class Ext.data.Store which contains "reader: new Ext.data.XmlReader", but how can I know when my AJAX request is over?

I need help please.thanks


please

dfenwick
29 Apr 2007, 2:35 PM
please

Welcome to Ext.

You can add an event handler for the 'load' event that will fire when the dataset is finished loading. It will look something like this:


ds.on('load', function(store, records, options) {
// store is the Store object
// records is an array of the Record objects retrieved
// options is the configuration object passed on the load()

// Process whatever you want here. The dataset will be loaded at this point
});

bagus
3 May 2007, 2:07 PM
I'm wondering where this on load code goes.

I'm working with the edit-grid.html example:
http://extjs.com/deploy/ext/examples/grid/edit-grid.html

What I've been trying is to put this on('load'...) after the ds.load(); statement.




//...all code is the same from the example until after this ds.load(); statement:
ds.load();

ds.on("load", doSomething());

function doSomething() {
//debugger; //the function works if this is uncommented, but doesn't as is.
myPlant = ds.getAt(0);
myPlantCommon = myPlant.get('common');
alert(myPlantcCommon);
}


I'm finding that the store objects in my doSomething() function aren't there unless I put a debugger; statement in. That seems to be giving the data time to actually load. If I remove the debugger; statement, it doesn't work. Any ideas why? Am I supposed to have this ds.on("load", ...) statement somewhere else than right after the ds.load()? Is there something else I'm missing?

jsakalos
3 May 2007, 2:24 PM
Instead of this:

ds.on("load", doSomething());try this:

ds.on("load", doSomething);

matjaz
4 May 2007, 2:24 AM
For event you must pass function reference. In your case you call this function and pass null to event (because function does not return anything). You could call function if this function returns reference to function which you want to call on event.

Even better, you can add function as anonymous if you use it just for event:

ds.on("load", function() {
var myPlant = ds.getAt(0);
var myPlantCommon = myPlant.get('common');
alert(myPlantCommon );
});
P.S. I added var to variables... ;)

bagus
4 May 2007, 7:40 AM
Brilliant!

Thanks. Here's another question related to this post. dFenwick posted this code:


ds.on('load', function(store, records, options) {
// store is the Store object
// records is an array of the Record objects retrieved
// options is the configuration object passed on the load()

// Process whatever you want here. The dataset will be loaded at this point
});

I'm curious as to his passing store, records and options into this function.

In my doSomething function, I used : var myPlant = ds.getAt(0); I also know how I could use ds.each. But I am using them with out passing the store into the function. And records are a part of the store object, so what would be the point of passing them in separately?
What is the 'configuratoin object passed on the load();

Is this a worthwhile pattern to follow or should I just make my own function? My goal is to collect data to send back to the server and ultimately update a database.

Thanks.
Bagus

jsakalos
4 May 2007, 7:47 AM
This is event handler so you do not pass anything, instead, the store object fires that event when data is loaded.

see: http://extjs.com/deploy/ext/docs/output/Ext.data.Store.html#event-load (http://extjs.com/forum/../deploy/ext/docs/output/Ext.data.Store.html#event-load)

matjaz
4 May 2007, 8:01 AM
bagus:
You could assign this event to function which does not have access to ds because of scope, so because of this, arguments are passed.

But now I'm confused... you want to update values on "load" event, which is fired (once) when data is loaded. This doesn't make sense.

bagus
4 May 2007, 10:09 AM
no, I'm just messing with the 'on load' to get things going.

I assume I'll end up using a function that comes from a button being clicked on the page.

Thanks.

Now onto getting the data back to the server. but that's a separate thread.

jsakalos
4 May 2007, 10:13 AM
Just distinguish between load method and load event. Same names is coincidence they are totally different things.

dfenwick
4 May 2007, 10:58 AM
Brilliant!

Thanks. Here's another question related to this post. dFenwick posted this code:


ds.on('load', function(store, records, options) {
// store is the Store object
// records is an array of the Record objects retrieved
// options is the configuration object passed on the load()

// Process whatever you want here. The dataset will be loaded at this point
});

I'm curious as to his passing store, records and options into this function.

In my doSomething function, I used : var myPlant = ds.getAt(0); I also know how I could use ds.each. But I am using them with out passing the store into the function. And records are a part of the store object, so what would be the point of passing them in separately?
What is the 'configuratoin object passed on the load();

Is this a worthwhile pattern to follow or should I just make my own function? My goal is to collect data to send back to the server and ultimately update a database.

Thanks.
Bagus

Embrace the power of Ext. It hands it all directly to you. When you add the store for use, it's bi-directional. You update records in the store and it will post them back to the server for you. There's no middle man involved. All you need to do is build the backend to catch the update.

As far as the question about the event handler is concerned, all of the event handlers defined in Ext have a signature. They pass you some set of arguments. Whether or not you take action on those arguments is your business, but they're usually useful (and also typically well formed.)