View Full Version : strange: code line execution happening twice or more after event

13 Aug 2011, 1:11 AM

I have set up a MVC structure in Ext 4, with a form (called "headerformpanel") and a grid (with a store called "contactsstores"). The idea is that any field change in the form should refilter the store (something I achieved before without problems in Ext 3.3, without MVC).
At first things seem ok with this part of code in the init part of the controller:


'headerformpanel field':{
change: this.onChange

and then, in the function definitions:

onChange: function(){

This does what we can expect: every change in any form field is seen as ONE 'change' message in the console

However, if I do something more than a console log, ie. reloading the store like this:

onChange: function(){
Ext.widget('contactsstore').load(function(records, operation, success) {
console.log('loaded records');

then something strange happens: I get one 'change' console message (as before), but the store loads TWICE (as I can see in Firebug), strangely enough followed by only ONE 'loaded records' message....
Adding more lines of code (other than console logs) to the same function results somethimes in even more reloadings of the store, making the whole setup virtually unusable.

Anybody an idea of what's going on here?

Many thanks in advance....

13 Aug 2011, 3:17 PM
How are you determining that the store loads twice? 2 requests to the server?

Ext.widget() will be creating a new store. Does your class definition for contactsstore include autoLoad: true or some other code to perform a load at creation time?

Try getting rid of the load() part:


Do you still see an Ajax request?

If that doesn't explain it, try putting a breakpoint on the line:


in the doRequest() method of Ext.data.proxy.Ajax. How many times is that line hit? Does it correspond to all of the requests you see in Firebug?

Try using a different browser. Do you see the same problem in Chrome, for example? It's always a good idea to double check that Firebug is telling the truth when something mysterious is happening.

15 Aug 2011, 2:19 AM
Thank you for your reply . Indeed there was an autoload issue. And I was not aware of the fact that Ext.widget would create a new store, that was not wat I wanted. In the mean time I found out dat Ext.getStore('contactsstore') was the better way to go.
I'm just still getting used to Ext 4 and the new ways of organising things and referencing to components in MVC.
The API docs are fine (although I would love to see more than one MVC example), but what I miss is a 4.0 version of books like "Extjs in Action"...

Best regards, Marc