-
5 Oct 2009 1:12 PM #1
Extended Class and Calling Custom Function
Extended Class and Calling Custom Function
I am trying to call a function within my extended Ext.Window without success. I have reviewed the Extjs, forum and Google docs and need a little clarification as to why my closeWindow() call does not work (can't step into it with FBug). Thank you in advance. Here is my code (abbreviated)...
Code:// bo file Application.UX.Widget = Ext.extend(Ext.Window, { initComponent:function() { Ext.apply(this, { title: 'Blah-Blah' ,modal: true ,layout: 'border' ,items: [ { region: 'north' ,... } { region: 'center' ,... ,bbar: [ {...} ,{ text: 'Cancel' ,handler: function() { Ext.MessageBox.confirm( 'Cancel' ,'Really?' ,function(answer) { if (answer === 'yes') { this.closeWindow(); // <<--Ends here without error alert('func called successfully'); } } ) } } ] } ] } } // eo initComponent ,closeWindow:function() { this.close(); } //eo closeWindow } ); Ext.reg('widget', Application.UX.Widget); // eo file
-
5 Oct 2009 1:29 PM #2
You're out of scope... In the code you posted 'this' is the message box. You need to specify a scope in your confirm call:
Code:Ext.MessageBox.confirm('Cancel','Really?',function(answer) { if (answer === 'yes') { this.closeWindow(); // <<--Ends here without error alert('func called successfully'); } },this);
-
5 Oct 2009 5:13 PM #3
Because you are providing a new anonymous function to the confirm method.
Within the anonymous function, this does not refer to your extended window object.
Use the scope param (4th param of the confirm method) to remedy.
-
5 Oct 2009 8:13 PM #4
Thanks zhegwood and dah2000. After inspecting my code block I noticed that I did choose the right overloaded function (with the 4th param being 'this'). I am able to elicit the confirmation dialog but when I break on line: this.closeWindow(), I am unable to reach the function closeWindow. Any other suggestions? All ears, literally.
Code:// bo file Application.UX.Widget = Ext.extend(Ext.Window, { initComponent:function() { Ext.apply(this, { title: 'Blah-Blah' ,modal: true ,layout: 'border' ,items: [ { region: 'north' ,... } { region: 'center' ,... ,bbar: [ {...} ,{ text: 'Cancel' ,handler: function() { Ext.MessageBox.confirm( 'Cancel' ,'Really?' ,function(answer) { if (answer === 'yes') { this.closeWindow(); // <<--Ends here without error alert('func called successfully'); } } , this // Sorry, forgot to include in original post :( ) } } ] } ] } } // eo initComponent ,closeWindow:function() { // <-- Never reach the function! this.close(); } //eo closeWindow } ); Ext.reg('widget', Application.UX.Widget); // eo file
-
5 Oct 2009 9:08 PM #5
You need to set the scope on the button handler as well.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
5 Oct 2009 9:17 PM #6
-
5 Oct 2009 9:17 PM #7
Or capture this and use it:
Code:Application.UX.Widget = Ext.extend(Ext.Window, { initComponent:function() { var me = this; // <-- use "me" when wanting to access the Window instance in closures declared WITHIN initComponent Ext.apply(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
