【发布时间】:2012-02-10 14:40:55
【问题描述】:
我正在使用 ExtJS 4.0.7,是 Ext 的新手,并且正在使用新的 MVC 架构。我有一个 RadioGroup,在更改后,我想用它来显示更多 UI 元素。问题是,RadioGroup 的 change 事件触发了两次。我假设这是因为两个 Radios 都会触发一个事件以改变它们的值。
有没有办法监听 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');
}
【问题讨论】:
-
已确认 (fiddle)。看起来像一个错误。
-
这不是一种解决方法。我只创建了该错误的展示。
-
抱歉,我说的是我发布的内容。这是一种解决方法:将选择器更改为“#WheatChoice radio”并使用事件侦听器中的逻辑来忽略任何不等于 true 的新值。
-
我发现 radiogroups 和 checkboxgroups 在 4.x beta 中基本上无法使用...最好等待 RTM 版本