Обработка кнопок ExtJS

Как лучше всего добавить функцию к кнопке? (конкретно по объему)

Грязный пример:

form.Login= function(config){
if ( typeof config !== 'object' ) { config = {}; }



    var tbarBottom = {
    xtype: 'toolbar',
    dock: 'bottom',
    items: [{
        xtype:'spacer'
    },{
        text: 'Reset',
        handler:function(button,event){
            console.log(this); // ehh... how do I this.reset() from here? 
                              //( "this" is the buttons scope, not the forms scope )

        }]
    }
    config.dockedItems= [tbarBottom];
    form.Login.superclass.constructor.call(this,config);

Ext.extend( form.Login, Ext.form.FormPanel,{

reset: function() {
    this.reset()// I want to call this function
}

});

Я видел примеры в ExtJs 4 с использованием

this.up('form').reset();

и я тоже могу

this.ownerCt.ownerCt.reset()

Но обоим как-то очень неловко. ( .up гораздо меньше, хотя, поскольку я играю с сенсорным экраном, я не думаю, что «вверх» - это вариант)


person Alex    schedule 23.08.2011    source источник


Ответы (1)


Использовать это

{
    text: 'Reset',
    handler:function(button,event){
    console.log(this); // ehh... how do I this.reset() from here? 
                              //( "this" is the buttons scope, not the forms scope )
    },
   scope : this
} 
person Varun Achar    schedule 23.08.2011
comment
Из любопытства, это то, что можно сделать во всех javascript, или это что-то, что реализует ext? - person Alex; 23.08.2011
comment
Область действия может быть передана любой функции, например yourFuction.call(yourScope, function-Arguments) . Определение области, как у меня в приведенном выше коде, - это способ Ext Js передать объект области. - person Varun Achar; 23.08.2011