Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind click event for all buttons in app

Tags:

extjs

How can I bind event for all buttons in my ExtJS app? like JQuery:

$('button').click(function(el) {
    console.log($(el).getattr('value'));
});
like image 908
ycuk Avatar asked Oct 06 '22 08:10

ycuk


1 Answers

Two ways:

If you're writing a full app following Ext's MVC pattern, you have to instantiate an Ext.Application and use a controller with code like the following

  • http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Controller
  • http://docs.sencha.com/ext-js/4-1/#/guide/application_architecture

Sample Code

Ext.define('MyApp.controller.Buttons', {
    extend: 'Ext.app.Controller',

    init: function() {
        this.control({
            'button': {
                click: function() { ... }
            }
        });
    }
});

The hacked up way is to do a query and bind a separate handler for each button

Ext.Array.each(Ext.ComponentQuery.query('button'), function(btn)) {
  btn.on('click', function() {...});
};
like image 146
Juan Mendes Avatar answered Oct 10 '22 02:10

Juan Mendes