2009-01-05 111 views
7

我有一些困难访问在radiogroup中选定的单选按钮的值。基于论坛和网络上其他帖子的讨论,我尝试了许多不同的方法。不幸的是,运气不够好(或熟练)。基于下面的FormPanel配置,我希望有人能够告诉我如何获得组中'mainPhone'中选定电台的值。Ext RadioGroup - 如何访问所选单选按钮的值?

谢谢!

想要更新以表明我能够从stackoverflow获得响应,而EXT-JS论坛没有提供任何帮助。方法去stackoverflow!

马特

function createForm(elem) { 
var myForm2 = new Ext.form.FormPanel({ 
    renderTo:elem, 
    width:425, 
    frame:true, 
    style:"margin: 10px auto 10px auto;", 
    items: [{xtype:'fieldset', 
      title: 'Contact Info', 
      autoHeight:true, 
      items :[new Ext.form.RadioGroup({ 
         fieldLabel: 'Main Phone', 
         vertical: false, 
         id:"mainPhone", 
         items: [ 
          {boxLabel: 'Home', name: 'id-1', inputValue: 'H', checked:true}, 
          {boxLabel: 'Work', name: 'id-1', inputValue: 'W'}, 
          {boxLabel: 'Other', name: 'id-1', inputValue: 'O'} 
         ]  

        }), 
        new Ext.form.TextField({ 
        id:"frm_CreateCustomerHomePhone", 
        fieldLabel:"Home Phone", 
        width:275, 
        allowBlank:true 
       }), 
       new Ext.form.TextField({ 
        id:"frm_CreateCustomerWorkPhone", 
        fieldLabel:"Work Phone", 
        width:275, 
        allowBlank:true 
       }) 
        new Ext.form.TextField({ 
        id:"frm_CreateCustomerOtherPhone", 
        fieldLabel:"Other Phone", 
        width:275, 
        allowBlank:true 
       }) 
    ]}]});    
} 

回答

9

这是胡乱猜测的东西,但这个怎么样:

myForm2.getForm().getValues()['id-1']; 
+0

这一个做到了!非常感谢 – Matty 2009-01-06 14:05:33

-2
function get_radio_value() 
{ 
    for(var i=0; i < document.myForm.mainPhone.length; i++) 
    { 
     if(document.myForm.mainPhone[ i ].checked) 
     { 
      return document.myForm.mainPhone[ i ].value; 
     } 
    } 
} 
5

收音机组本身的方法getValue()将返回的对象检查,如果有的话,否则,它返回undefined。我使用的是extjs 3.0,而且我认为它没有什么区别,也许它在最后一个“getValue”),我使用的是extjs 3.0,而且我也使用extjs 3.0,我的radiogroup配置与你的略有不同。

var checkedItem = Ext.getCmp('mainPhone').getValue(); 

if (checkedItem == undefined) return ''; 

return checkedItem.getGroupValue(); 
// The getGroupValue will return the value of the checked option in a group, 
// unfortunately, it only seems to work on the items and not the radiogroup 
// itself 
1

,如果你想获得该领域的具体数值,使用

myForm2.getForm().findField('id-1').getGroupValue(); 
3

我知道这个问题是旧的,但我加入这个以供参考。以下片段适用于Ext 2.2 afaik。

Ext.getCmp("mainPhone").items.get(0).getGroupValue(); 
0

不确定这是否太简单,但我能够使用'inputValue'属性访问值(在分机3.3.1)。

var radio = ...; 
var value = radio.inputValue; 
2

Lo-Tan的答案适用于我。我也使用extjs 2.2.1 像我一样,你可能没有ext.Form.Formpanel,只是一个搜索框和一个radiogroup。我使用此代码从无线电组中获取值。

我的单选按钮组:

var begrens_sok = new Ext.form.RadioGroup({ 
fieldLabel: 'Begrens søket', 
columns: 1, 
name: 'sokspecs', 
id:'sokspecs', 
items: [ 
     {boxLabel: 'Scientific name', name: 'sokspec', inputVale:'SN'}, 
     {boxLabel: 'Norsk navngruppe', name: 'sokspec', inputValue:'NNG'}, 
     {boxLabel: 'Norsk navnart', name: 'sokspec', inputValue:'NNA'}, 
     {boxLabel: 'Prosjektsøk', name: 'sokspec', inputValue:'PROJ'}, 
     {boxLabel: 'Fritekst søk', name: 'sokspec', inputValue:'FSOK', 'id':'sokspec', checked: true} 
] 
    }); 

为了让我用这个检查的单选按钮值:

var radiovalue= Ext.getCmp('sokspecs').items.get(0).getGroupValue() 
0

如果你使用MVC,也许你尝试使用IDS忽略。所以其中一个解决方案,然后获得价值变化事件是

change : function(radioButton, newValue, oldValue, eOpts){ 
     console.log(newValue.individual); 
} 
相关问题