PDA

View Full Version : how to stop load event from loading



iceblast_01
14 Aug 2009, 9:55 PM
how to stop load event from loading?
i have a code here

function something()
{

var list = new Ext.data.JsonStore({
url: 'list.php',
root: 'someroot',
fields: [
'field1','field2'
]
});
list.load();
list.on('load',function(a,records)
{
//some code...
});
}
Ext.onReady(function(){

Ext.get('button').on('click',function()
{
something();
});

});

if i click the button, then the store is not finished loading, then i click the button again,
the store loads again(in this case it would loads twice), it would enter the on('load') event on how many times the store loads, the problem is that it would execute the code inside the on('load') event serveral times, i used the load event because i like to get some info from the records, is there a way to enter the list.on('load') event only once? ignore the previous loads and get only the last?

Copernicus
15 Aug 2009, 1:38 AM
You want the store load method to not get called every time the store is loaded?

Wouldnt it be better to only load the store once if thats what you really want?

iceblast_01
15 Aug 2009, 2:48 AM
i do just load it when i want it, the button is somesort of refresh button, so i reload the store
when i click the button, so everytime i click the button the store reloads, i use the
store.on('load',function(){ ... }); to get the records, and use the records for my program,
because i can't just load and get the records, because when i use store.load(); then try to
get the records, store.getCount() returns 0, so i used the store.on('load',function(){ ... });
to get the records.

here's a scenario, a user clicked the button, so the store is loading... so its taking a while
for the server to reply and return the json records... the loading isnt complete yet, the
user got impatient, clicked the button again, so the store reloads again, so the store sent
another request to the server so it takes a while again, the 1st load gets completed, it
enters the store.on('load',function(){ ... }); so the codes inside gets executed, then the
2nd load gets completed, it again enters the store.on('load',function(){ ... }); and the
codes inside gets executed, again, i only want the last load to be proccessed, and ignore
the old loads that wasnt completed on time

Copernicus
15 Aug 2009, 2:57 AM
I see.

Why not simply disable the button in the "beforeload" event and enable it in the "load" event when the store has finished loading?

iceblast_01
15 Aug 2009, 7:48 AM
wow tnx! nice idea ill try that on monday give you feed back by then, i love this forum tnx again