如何使用extjs 4获得radiogroup检查值?

问题描述 投票:2回答:4

我使用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());
        }
    }
    });

我想在检查后获得已检查单选按钮的值。为此,我使用了听众,但没有工作。我是对的还是需要用其他方式。请帮帮我。

extjs extjs4 extjs4.1
4个回答
2
投票

我尝试了很多解决方案,只有一个解决方案。希望能帮助到你

listeners: {
     change : function(obj, value){ 
         alert(value.individual);
        }
    }

3
投票

您可以使用getChecked()功能


2
投票

你的代码看起来不错。变更事件被解雇了。只有改变你必须做的是

listeners: {
     change : function(obj, value){ 
         alert(value.rb);
        }
    }

其中value.rb将为您提供所选单选按钮的值。


0
投票

这也可以写成一般来处理你所有的无线电组。值(在我的示例中使用的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');
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.