【问题标题】:How to add a listener to some buttons extjs如何为某些按钮添加监听器 extjs
【发布时间】:2013-10-03 15:25:30
【问题描述】:

我是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 复制答案,但它仍然无法正常工作。它不注册事件。

【问题讨论】:

    标签: button listener extjs4.1


    【解决方案1】:

    为按钮添加监听器非常简单。将按钮与外面的功能绑定起来很困难。但是找到了按钮的监听器:

    {
        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!');
        }}
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      • 2015-07-02
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 2012-10-10
      相关资源
      最近更新 更多