为应用中的所有按钮绑定点击事件 [英] Bind click event for all buttons in app

查看:97
本文介绍了为应用中的所有按钮绑定点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ExtJS应用程序中绑定所有按钮的事件?
喜欢JQuery:

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

$('button').click(function(el) {
    console.log($(el).getattr('value'));
});


推荐答案

两种方式:

如果您正在使用Ext的MVC模式编写完整的应用程序,则必须实例化一个 Ext.Application ,并使用带有以下代码的控制器

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

示例代码

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() {...});
};

这篇关于为应用中的所有按钮绑定点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆