ExtJS 4 RadioGroup Change Event两次爆发

the*_*kua 4 extjs extjs4 extjs-mvc

我正在使用ExtJS 4.0.7,我是Ext的新手,并且正在使用新的MVC架构.我有一个RadioGroup,改变后,我想用来揭示更多的UI元素.问题是,更改事件会为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 }
     ]
}]
Run Code Online (Sandbox Code Playgroud)

这是我的控制器中的相关代码:

init: function() {
     this.control({
         '#WheatChoice': {
            change: this.onWheatChange
         }
     });
},

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

jth*_*rau 5

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

evant说这将用4.1修复,所以它肯定是一个bug.

但是,您可以非常轻松地处理这种情况:

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

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

}  
Run Code Online (Sandbox Code Playgroud)

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