循环遍历fieldset并获取RadioGroup检查的输入值

时间:2014-03-17 13:10:32

标签: extjs radio-group

我有一个包含两个RadioGroup的字段集,每个RadioGroup有两个RadioField:

 xtype: 'fieldset',
title: 'Advanced',
autoHeight : true,
id : 'advancedfieldset',
collapsible : true,
width : 280,
margin : 5,
labelWidth : 280,
items : [
    { xtype : 'radiogroup',
    name: 'myGroup',
    vertical: true,
    items :[
         {
          boxLabel : 'duplicate',
          name:'1',
          id:'hid_dup', 
          inputValue: 'Yes'
         },
        {
         boxLabel : 'not duplicate', 
         name: '1',
         id:'hid_not_dup',
         inputValue: 'Yes'
         }
       ]},
    {xtype : 'radiogroup',
    name: 'myGroup2',
    vertical: true,
    items :[{
        boxLabel : 'state',
        name: '2',
        id:'hid_state', 
        inputValue: 'Yes'
        },
       {
        boxLabel : 'not state',
        name: '2',
        id:'hid_not_state',
         inputValue: 'Yes'
       }
]
}
]

我想循环遍历字段集并返回每个放射组的已检查无线电的inputvalue

我喜欢这个:

var advancedFieldset = parametersRef.down('fieldset[id=advancedfieldset]');

 advancedFieldset.items.each(function (item) {
            if (item.xtype =='combo'){
            filters_values_arr.push(item.getRawValue());
            }else{
                alert(parametersRef.getForm().getValues()[item.name]); //it gives me the two radiofields inputValue (although only one of them is checked) of the FIRST RADIO GROUP ONLY
                alert(item.items.get(1).getGroupValue());//same here
            }
        });

但它没有用,请帮助!

2 个答案:

答案 0 :(得分:0)

这对你来说够了吗?或者我可以继续根据ComponentQuery获取具体记录!

这是小提琴:Get selected radio values

Ext.create('Ext.form.Panel', {
    title: 'RadioGroup Example',
    id: 'form-panel',
    width: 300,
    height: 200,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items:[
        {
            xtype: 'radiogroup',
            fieldLabel: 'Group One',
            // Arrange radio buttons into two columns, distributed vertically
            columns: 2,
            vertical: true,
            items: [
                { boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
                { boxLabel: 'Item 2', name: 'rb', inputValue: '2', checked: true},
                { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
                { boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
                { boxLabel: 'Item 5', name: 'rb', inputValue: '5' },
                { boxLabel: 'Item 6', name: 'rb', inputValue: '6' }
            ]
        },
        {
            xtype: 'radiogroup',
            fieldLabel: 'Group Two',
            // Arrange radio buttons into two columns, distributed vertically
            columns: 2,
            vertical: true,
            items: [
                { boxLabel: 'Item 1', name: 'cb', inputValue: '1' },
                { boxLabel: 'Item 2', name: 'cb', inputValue: '2' },
                { boxLabel: 'Item 3', name: 'cb', inputValue: '3' },
                { boxLabel: 'Item 4', name: 'cb', inputValue: '4' },
                { boxLabel: 'Item 5', name: 'cb', inputValue: '5' },
                { boxLabel: 'Item 6', name: 'cb', inputValue: '6', checked: true }
            ],
            listeners: {
                change: function() {
                    var fp = Ext.getCmp('form-panel');
                    var out = Ext.ComponentQuery.query('radio');

                    Ext.Array.each(out, function(rb) {
                        if (rb.checked === true) {
                            console.log(rb.inputValue);
                        }
                    })
                }
            }
        }
    ]
});

答案 1 :(得分:0)

我设法让它像这样工作:

advancedFieldset.items.each(function (item) {

            var myGroup= myView.down('radiogroup[name='+item.name+']').getChecked()[0];
              //find the value of the selected Radio button
            alert("Label is: " + myGroup.boxLabel +
               " and Value is: " + myGroup.getGroupValue());            
        });