日期:2014-05-16  浏览次数:20349 次

ExtJS4.2:为radio绑定事件,有什么简便的写法嘛?
Ext.onReady(function() {
    var panel=new Ext.Panel({
     renderTo:'panel',
     frame:true,
     width:80,
     height:80,
     title:'Radio',
     items:[{
         id:'radio1',
         xtype:'radio',
     boxLabel:'选项一',
     name:'radio',
     inputValue:'1',
     checked:true
     },{
         id:'radio2',
         xtype:'radio',
         boxLabel:'选项二',
     name:'radio',
     inputValue:'2'
     }]
    });
    Ext.getCmp('radio1').on('focus',function(){
     console.log("info");
    });
    Ext.getCmp('radio2').on('focus',function(){
     console.log("info");
    });
});


这样写有100个按钮我就需要绑定100次,我知道有种方法好像是使用RadioGroup,还有其他办法解决这个问题吗
------解决方案--------------------
id起得规则点就一个for循序绑定

或者用select放一次选择需要的对象添加事件

Ext.select('input[id^=radio]').on('click', function () { console.log(this) });