1
votes

I want to pass parameter "aaa" to disableFlied function, but the code below didn't work:

init: function() {

    this.control({
        '#speedCheck': {
            change :this.disableFlied("aaa")
        }
    });

},
disableFlied: function(cmpName){

    var a = Ext.getCmp(cmpName);
    a.setDisabled(!a.isDisabled());

}

How to pass "aaa" to disableFlied function?

1

1 Answers

5
votes

You must pass a function as event handler, here you're passing the result of calling disableField yourself (i.e. nothing since this method doesn't return anything). What you need to do is create another function that passes the desired parameter. In Ext, you can do that with the Ext.bind function.

Here's how you should use it:

this.control({
    '#speedCheck': {
        change: Ext.bind(this.disableField, this, ['aaa'])
    }
});

This will create a closure around the disableField method. This is equivalent to this vanilla javascript code:

    '#speedCheck': {
        // This is the default scope, but I prefer to make it
        // explicit that the handler must be called in the
        // current scope
        scope: this
        ,change: function() {
            // When this function is called, it will call
            // disableField with the desired parameter
            this.disableField('aaa');
        }
    }