2013-09-27 33 views
1

我是extjs的新手(使用ext.js 4.1),我仍然在學習它,但現在我必須做的事情有點棘手,我會喜歡有更有經驗的開發人員的建議。這個問題是關於這些按鈕:如何向某些按鈕添加偵聽器extjs

{ 
    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

將監聽器添加到按鈕非常簡單。它是綁定與它之外的功能是困難的。然而,發現按鈕的收聽者:

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