【问题标题】:Loop through fieldset and get RadioGroup checked input value遍历字段集并获取 RadioGroup 检查的输入值
【发布时间】:2014-03-17 13:10:31
【问题描述】:

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

 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
            }
        });

但它不起作用,请帮助!

【问题讨论】:

    标签: extjs radio-group


    【解决方案1】:

    这对你来说足够了吗?或者我可以根据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);
                            }
                        })
                    }
                }
            }
        ]
    });
    

    【讨论】:

      【解决方案2】:

      我设法让它像这样工作:

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

      【讨论】:

        猜你喜欢
        • 2022-01-08
        • 1970-01-01
        • 1970-01-01
        • 2017-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-26
        相关资源
        最近更新 更多