PDA

View Full Version : A problem of using "this.",in a button's handler



safewolf
27 Sep 2008, 6:27 AM
hi,everyone

i have some problems in customer class now

this is my code:




Ext.onReady(function()
{
FormWindow = function(config) {
this.string = "dddd";
Ext.apply(this, config);
FormWindow.superclass.constructor.call(this, {
title: this.title,
iconCls: 'feed-icon',
autoHeight: true,
resizable: false,
plain:true,
modal: true,
autoScroll: true,
closeAction: 'hide',
items: this.form,
buttons:[
{text:'Button',
handler:function(){alert(this.string);}
}
]
});
};

Ext.extend(FormWindow, Ext.Window, {
form : new Ext.Panel({width:400,height:200}),
title : "Windows"
});

win = new FormWindow();
win.show();

});









in the line of the button's handler, i want to alert this.string

but there's an error said this.string is undefined

how can i use the this.*** in the handler?:)

evant
27 Sep 2008, 6:58 AM
Because you need to set the scope of the handler.

http://extjs.com/deploy/dev/docs/?class=Ext.Button&member=scope

mjlecomte
27 Sep 2008, 8:05 AM
http://extjs.com/learn/Tutorial:What_is_that_Scope_all_about2#Ext.27s_scope_config