Extjs 如何从Ext Js 4中的控制器引用多个radiogroup?
我有一个由两个放射组组成的小组。我正在尝试从控制器文件将更改事件绑定到这些项。不想在视图文件中使用侦听器配置 视图文件Extjs 如何从Ext Js 4中的控制器引用多个radiogroup?,extjs,extjs4,extjs4.1,radio-group,Extjs,Extjs4,Extjs4.1,Radio Group,我有一个由两个放射组组成的小组。我正在尝试从控制器文件将更改事件绑定到这些项。不想在视图文件中使用侦听器配置 视图文件 items : [{ xtype:'radiogroup', fieldLabel: 'Two Columns', // Arrange radio bu
items : [{
xtype:'radiogroup',
fieldLabel: 'Two Columns',
// Arrange radio buttons into two columns, distributed vertically
columns: 2,
id:'new_0',
vertical: true,
items: [
{ boxLabel: 'Item 1', name: 'rb1', inputValue: '1' },
{ boxLabel: 'Item 2', name: 'rb1', inputValue: '2', checked: true},
{ boxLabel: 'Item 3', name: 'rb1', inputValue: '3' },
{ boxLabel: 'Item 4', name: 'rb1', inputValue: '4' },
{ boxLabel: 'Item 5', name: 'rb1', inputValue: '5' },
{ boxLabel: 'Item 6', name: 'rb1', inputValue: '6' }
]
},
{
xtype:'radiogroup',
fieldLabel: 'Two Columns',
id:'new_1',
// Arrange radio buttons into two columns, distributed vertically
columns: 2,
vertical: true,
items: [
{ boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
{ boxLabel: 'Item 2', name: 'rb', inputValue: '2', checked: true},
{ boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
{ boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
{ boxLabel: 'Item 5', name: 'rb', inputValue: '5' },
{ boxLabel: 'Item 6', name: 'rb', inputValue: '6' }
]
}],
在控制器中,我尝试绑定更改事件,如下所示:
refs : [
{
ref :'myradio',
selector:'radiogroup'
}],
这里它指向第一个项目,不绑定第二个组的事件。如果我与ids绑定,则其工作正常。所以问题是如何将更改事件绑定到所有radiogroup,而不在选择器中传递ID。假设在一个窗格中,我有2个radiogroup项,并希望将更改事件绑定到每个radiogroup
非常感谢您的回答 你可以给每个放射组一个
itemId
,而不是id
。然后在控制器中,您应该能够引用每个radiogroup
,并将您想要的所有事件绑定到每个组。因此,您的控制器应如下所示:
...
refs: [
{
autoCreate: true,
ref: 'firstbtngroup',
selector: '#firstbtngroup', // itemId for first radio group
xtype: 'Ext.form.RadioGroup'
},
{
autoCreate: true,
ref: 'secondbtngroup',
selector: '#secondbtngroup', // itemId for second radio group
xtype: 'Ext.form.RadioGroup'
}
],
onFirstbtngroupChange: function(field, newValue, oldValue, eOpts) {
console.log('Hey you...');
},
onSecondbtngroupEnable: function(component, eOpts) {
console.log('Hey there again...');
},
onFirstbtngroupAfterRender: function(component, eOpts) {
console.log('Dude I just renedered.');
},
onSecondbtngroupDestroy: function(component, eOpts) {
console.log('Why would you destroy me!!!');
},
init: function(application) {
this.control({
"#firstbtngroup": {
change: this.onFirstbtngroupChange,
afterrender: this.onFirstbtngroupAfterRender
},
"#secondbtngroup": {
enable: this.onSecondbtngroupEnable,
destroy: this.onSecondbtngroupDestroy
}
});
}
...
这可以通过使用itemId来实现,但是我们如何为所有radiogroup绑定相同的事件。假设我们必须为每个放射组调用相同的函数,那么我们是否可以引用所有放射组,而不是为每个放射组重写相同的函数名,并在函数内部由id决定?