Hybrid View
-
2 May 2008 7:24 AM #1
Listeners and Scope
Listeners and Scope
Hi All,
I am trying to fire an event in my JS file to a listener rendered by lazy-initialization code, but the two don't want to talk to each other. Do I need to define a specific scope? They are both rendered on the same page..
JS
In my JSON lazy initialization code:Code:this.addEvents({'checkactive': true}); ..... this.grid.on('rowclick', function(grid, index, e) { if (sm.getCount() > 0) { this.fireEvent('checkactive', 'enabled'); } else { this.fireEvent('checkactive', 'disabled'); } }, this);
I've checked in FireBug and the fireEvent is run, but the listener never gets executed.Code:buttons: [{ "text": "Submit", "type": "button", "scope": this, "handler": function(){ submit(); }, "listeners": { "checkactive": function(isenabled) { alert(isenabled); }, scope:this } .....
Any ideas?
Thanks
-
2 May 2008 7:44 AM #2
this.grid.on('rowclick'....
You bind that handler function to whatever "this" is at that time. That is then what the 'checkactive' event is fire on.Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
2 May 2008 7:48 AM #3
Thanks Animal, what could it be binded to other than 'this'? I am not familiar with using different scoping definitions...
Thanks again
-
2 May 2008 7:59 AM #4
If you don't need it, don't use it.
But if you are writing "function soup" rather than a set of discrete Classes which manage their own internal state individually, then you are storing up trouble.Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
5 May 2008 11:42 PM #5
Thanks. I'm assuming by removing the scope on an event it would work across the dom of the active page? That would solve the problem I am having.
I have removed the scrope from the listener but how can I make the event global, currently this.fireEvent.... still does not execute the listener which is without scope.
Thanks
John
-
6 May 2008 12:01 AM #6
The things in red are the same. You have specified a rowclick handler to run, and passed this as the scope. So that is what the this in the handler will be.Code:this.grid.on('rowclick', function(grid, index, e) { if (sm.getCount() > 0) { this.fireEvent('checkactive', 'enabled'); } else { this.fireEvent('checkactive', 'disabled'); } }, this)Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642


Reply With Quote