gpt4 book ai didi

ExtJS 4 RadioGroup Change 事件触发两次

转载 作者:行者123 更新时间:2023-12-04 23:07:13 24 4
gpt4 key购买 nike

我正在使用 ExtJS 4.0.7,我是 Ext 的新手,并且正在使用新的 MVC 架构。我有一个 RadioGroup,在更改后,我想用它来显示更多 UI 元素。问题是,更改事件为 RadioGroup 触发了两次。我假设这是因为两个 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 }
]
}]

这是我的 Controller 中的相关代码:
init: function() {
this.control({
'#WheatChoice': {
change: this.onWheatChange
}
});
},

onWheatChange: function(field, newVal, oldVal) {
//this fires twice
console.log('wheat change');
}

最佳答案

http://www.sencha.com/forum/showthread.php?132176-radiogroup-change-event-fired-twice/page2

evant 说这将在 4.1 中修复,所以这绝对是一个错误。

但是,您可以很容易地处理这种情况:

//borrowing your function
onWheatChange: function(rg, sel) {
var selection = sel['wheat-selection'];

if (!(selection instanceof Object)) {
alert(selection);
}

}

var selection 将是新值。我知道它不能解决两个事件触发问题,但希望这会有所帮助!

关于ExtJS 4 RadioGroup Change 事件触发两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9229471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com