Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 4.2 Parameter in listeners function

I've got problem with my controller

Ext.define('app.controller.myController', {
    init: function() {
        this.control({
            '#myinputfield': {
                change: this.textFieldChange(parameter)
            }
        })
    },
    textFieldChange: function(parameter) {
      //do something
    }
});

its look like this the problem is when i give parameter here

change: this.textFieldChange(parameter)

then its fire up after site load and I don't know why.

without parameter its waiting for change event like it should can any1 help me please ?

like image 392
Arkadiusz P Avatar asked Aug 26 '13 07:08

Arkadiusz P


1 Answers

It is because:

change: this.textFieldChange here you are giving the reference for this function to this property

change: this.textFieldChange(parameter) here you are giving the result of the function to this property (which if we don't use return, then it will be undefined).

You can use the eOpts variable in the function definition, for custom parameter sending, see in Example:

Ext.define('app.controller.myController', {
    init: function() {
        this.control({
            '#myinputfield': {
                change: {
                    fn : this.textFieldChange,
                    params : {
                        param1: 'something'
                    }
                }
            }
        })
    },
    textFieldChange: function(textfield, newValue, oldValue, eOpts) {
        var params = eOpts.params;
        console.log(params.param1);
      //do something
    }
});
like image 66
Alexander.Berg Avatar answered Nov 11 '22 04:11

Alexander.Berg