4

I'm a newbie of extjs (using ext.js 4.1),I'm still learning it, but the thing that I have to do now is a little tricky and I would like to have the advice of a more experienced developer. The problem is regarding these buttons:

{
    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;
        }
}
}
}

As you can see there is a listener, it was working when the buttons were only checkboxes (i'm changing them now to be checked only one at time). Now I assume I have to change the listener to many more listeners, one for each button. But the questions are:

  • How do i get the value from the buttons?

  • How should the function of the listener be structured at the level of the parameters of the function?

  • I will have to change the "checked" variable which filters the store...

I'm copying from this answer, but it doesn't work still. It doesn't register the event.

4

1 回答 1

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!');
    }}
}
于 2013-09-30T09:23:21.423 回答