( this). , , , - :
var getUrl = 'test';
this.items.add(
new Ext.form.Checkbox(
{
listeners: {
check: function(checkbox, checked) {
alert(getUrl);
},
}
)
)
If you really want the parent to be accessible as thisin an event handler, you can use Ext.Function.bindto change the scope:
this.getUrl='test';
this.items.add(
new Ext.form.Checkbox(
{
listeners: {
check: Ext.Function.bind( function(checkbox, checked) {
alert(this.getUrl);
}, this ),
}
)
)
Update: Ext.Function.bindis an ExtJS 4 function. If you use ExtJS 3.x or lower, you can use Function.createDelegateat the same end:
this.getUrl='test';
this.items.add(
new Ext.form.Checkbox(
{
listeners: {
check: function(checkbox, checked) {
alert(this.getUrl);
}.createDelegate(this)
}
)
)
source
share