如何将侦听器添加到某些按钮extjs

时间:2013-09-27 10:49:54

标签: button listener extjs4.1

我是extjs的新手(使用ext.js 4.1),我还在学习它,但我现在要做的事情有点棘手,我想得到更有经验的建议开发商。问题出在这些按钮上:

{
    xtype : 'checkboxgroup',
store : checked,
columns : 3,
vertical : false,
singleSelect: true,
items : [
{
    xtype: 'button',
    text: 'name',
    width: 75,
    toggleGroup: 'mygroup',
    enableToggle: true
}, {
    xtype: 'button',
    text: 'email',
    width:75,
    toggleGroup: 'mygroup',
    enableToggle: true
}, {
    xtype: 'button',
    text: 'id',
    width: 75,
    toggleGroup: 'mygroup',
    enableToggle: true
}
],
listeners : 
{
    'change' :
// store checked field
function(th, newValue, oldValue) {
    var ics = th.items.items;
    for (i = 0; i < 3; i++) {
        checked[i] = ics[i].checked;
        }
}
}
}

正如你所看到的那样,有一个监听器,当按钮只是复选框时它正在工作(我现在正在改变它们以便只检查一个)。现在我假设我必须将监听器更改为更多的监听器,每个按钮一个。但问题是:

  • 如何从按钮中获取值?

  • 如何在函数参数的层次上构建侦听器的功能?

  • 我将不得不更改过滤商店的“已检查”变量...

我正在从this回复,但它仍无效。它不会注册该事件。

1 个答案:

答案 0 :(得分:3)

向按钮添加侦听器非常简单。它将底部与其外部的功能绑定起来很困难。然而,找到按钮的监听器:

{
    xtype: 'button',
    text: 'name',
    width: 75,
    toggleGroup: 'mygroup',
    enableToggle: true,
    listeners: {
    click: function() {
    //this == the button, as we are in the local scope
        this.setText('I was clicked!');
    }}
}