Extjs RadioGroup二选一

对上边文章改进了一下,通过一个函数:

function check(r,b){
        var firstRadio=Ext.getCmp('radio0');
        var secondRadio=Ext.getCmp('radio1');
        if(r.getId()==='radio0'){
		if(b){secondRadio.setValue(false);firstRadio.setValue(true)}
		else{secondRadio.setValue(true);firstRadio.setValue(false)}
        }else{
        	if(b){secondRadio.setValue(true);firstRadio.setValue(false)}
		else{secondRadio.setValue(false);firstRadio.setValue(true)}
        }
};

同时还要设置第一个radio的checked为true。通过check事件调用上边的方法就好了。

{xtype:'radio',boxLabel:'并且',checked:true,id:'radio0',listeners:{'check':function(r,b){check(r,b)}}},{xtype:'radio',boxLabel:'或者',id:'radio1',listeners:{'check':function(r,b){check(r,b)}}}]
原文地址:https://www.cnblogs.com/sunzhenxing19860608/p/1841394.html