我使用extjs 4作为单选按钮。代码如下
var mychkbxgrp = Ext.create('Ext.form.RadioGroup',{
fieldLabel: 'Layer',
columns: 1,
items:[{
boxLabel: 'District', name: 'rb', inputValue: 'district',itemId:"DIS"
},{
boxLabel: 'SubDistrict', name: 'rb', inputValue: 'Subdistrict',itemId:"sub"
},{
boxLabel: 'Village', name: 'rb', inputValue: 'Village'
},{
boxLabel: 'Road', name: 'rb', inputValue: 'Roads'
},{
boxLabel: 'Point', name: 'rb', inputValue: 'POINT'
}],
listeners: {
change : function(){
alert(this.getValue());
}
}
});
我想在检查后获得已检查单选按钮的值。为此,我使用了听众,但没有工作。我是对的还是需要用其他方式。请帮帮我。
我尝试了很多解决方案,只有一个解决方案。希望能帮助到你
listeners: {
change : function(obj, value){
alert(value.individual);
}
}
您可以使用getChecked()功能
你的代码看起来不错。变更事件被解雇了。只有改变你必须做的是
listeners: {
change : function(obj, value){
alert(value.rb);
}
}
其中value.rb将为您提供所选单选按钮的值。
这也可以写成一般来处理你所有的无线电组。值(在我的示例中使用的radioGroup)是RadioGroup,因此您可以使用
getChecked()like so:
listeners: {
change: radioGroupHandler
}
...
function radioGroupHandler(obj, radioGroup) {
var checked = radioGroup.getChecked();
if (checked.length) {
alert(radioGroup.getChecked()[0].getValue());
} else {
alert('nothing checked');
}
}