PDA

View Full Version : Scope question (who is this?)



cripkd
31 Oct 2009, 8:08 AM
I have a class that extends a panel, the class functions as a Grid plugin.
The class, amongst others, has 2 parameters, a referrence to a window and a referrence to a form.
I want to hide the window when the user clicks Cancel in the form.
Thing is that in the handler option of the Cancel button of the form "this" means the button, and not myclass, as in the class scope.
How then can i reference the window so that i can call hide on it? I guess I need to pass in the class scope to the button, but i have no idea how to do that.
Thanks.

Animal
31 Oct 2009, 8:55 AM
http://www.extjs.com/deploy/dev/docs/?class=Ext.Button&member=scope

cripkd
31 Oct 2009, 10:01 AM
Hmm..


init: function(grid){
this.grid = grid;
this.window = new Ext.Window({...});
var w = this.window;
this.form = new Ext.FormPanel({
...,
buttons: [{
text: 'Save'
},{
text: 'Cancel',
scope: ? ,
handler:function( ? ){console.log( ? )}
}]
});
}


I'm sorry, but I still don't get it.
I've tried both this.window (didn't expected it would work, why would this.window mean MY window as long as I'm the config list of a button of a form) and w. They all return the button as far as i see.
What am I getting wrong?

Animal
31 Oct 2009, 10:10 AM
What do you want the this reference of the Button handler to be?

Set the scope to that value.

cripkd
31 Oct 2009, 1:27 PM
I want it to be "this.window" where this refers to the class to which the init method belongs to, not to the form or the button used inside that method.
I understand what you are saying, but I guess my problem now is not how to pass that referece to the button, i got that, my problem is now accessing in the button context what used to be this.window in the class context , button that belongs to a form defined inside a method belonging to that class.


Class.window (this.window)
Class.method(){
f = new Form({
buttons:[
{
handler:function( ??? ){}
}
]
})
}
I've already tried handler:function( w ){} when scope is defined as this.window in the button config, but that still comes up as the button itself.
That part is unclear yet, what goes into the scope: option and what exactly goes into the funtion() bit ? I figured it can be anything in the function declaration, like w, as long as i've set my scope as the window. But i don;t know how to tell it WHAT window exactly.

Animal
31 Oct 2009, 1:29 PM
Y'what now?

Class.?????

You lost me

cripkd
31 Oct 2009, 1:37 PM
Ah, sorry, it's kinda late here, almost :)
I was trying to give you a quick look using some sort of stupid pseudocode, after which i resorted to almost real code :)

SO, i have a class, that has a a window and a form as properties.
The form rendres inside the window.
The window is referenced as this.window accross code in the class scope, or its methods.
But then i find myself inside the button scope of the form. Where this.window makes no sense i guess.
Thanks to your scope: option i now know how to pass the scope to the button, but i still don't know WHAT exactly to pass it, as i said, this.window makes no sense there, and i agree.