我正在使用ExtJS 4.0.7,是Ext新增的,並且正在使用新的MVC體系結構。我有一個RadioGroup,在更改時我想用它來顯示更多的UI元素。問題是,更改事件爲RadioGroup激發兩次。我假設這是因爲兩個無線電臺都會觸發一個事件,讓它們的值發生變化。ExtJS 4 RadioGroup更改事件兩次觸發
有沒有一種方法可以偵聽RadioGroup或Radios的相同名稱只會觸發一次的更改?在我使用jQuery和Flex的經驗中,我期望RadioGroup只能觸發一次。
這裏是在我看來,RadioGroup中代碼:
items: [{
xtype: 'radiogroup',
id: 'WheatChoice',
padding: '',
layout: {
padding: '-3 0 4 0',
type: 'hbox'
},
fieldLabel: 'Choose Model',
labelPad: 5,
labelWidth: 80,
allowBlank: false,
columns: 1,
flex: 1,
anchor: '60%',
items: [
{ xtype: 'radiofield', id: 'SpringWheat', padding: '2 10 0 0', fieldLabel: '',
boxLabel: 'Spring', name: 'wheat-selection', inputValue: '0', flex: 1 },
{ xtype: 'radiofield', id: 'WinterWheat', padding: '2 0 0 0', fieldLabel: '',
boxLabel: 'Winter', name: 'wheat-selection', inputValue: '1', checked: true, flex: 1 }
]
}]
下面是我的控制器相關代碼:
init: function() {
this.control({
'#WheatChoice': {
change: this.onWheatChange
}
});
},
onWheatChange: function(field, newVal, oldVal) {
//this fires twice
console.log('wheat change');
}
確認([小提琴](http://jsfiddle.net/molecule/4sTQQ/))。看起來像一個錯誤。 – 2012-02-10 14:57:20
這不是一個解決方法。我只創建了bug的展示。 – 2012-02-10 15:30:03
對不起,我正在談論我發佈的東西。這是一種解決方法:將選擇器更改爲'#WheatChoice radio',並使用事件偵聽器中的邏輯忽略任何不等於true的新值。 – 2012-02-10 15:37:30