当前位置: 代码迷 >> Ajax >> Ext 怎么获取radio的值?
  详细解决方案

Ext 怎么获取radio的值?

热度:552   发布时间:2012-02-19 19:43:39.0
Ext 如何获取radio的值? - Web 开发 / Ajax
有如下代码:
JScript code
{
                    id:'ipmac_mod',
                
                xtype: 'panel',
                                layout: 'table',
                    fieldLabel: '模式',
                     defaultType: 'radio',
                    isFormField: true,
                    items: 
                    [
                        {
                               id: 'type_local',name:'user_type',boxLabel: '模式1',value:'F',checked:editdata.data[0]['close_radius'],
                               listeners: 
                               {
                                check: function(radio,checked) 
                                {
                                    if(checked == true)
                                    {
                                        
                                        
                                        Ext.getCmp('radius').hide();
                                        Ext.getCmp('local').show();
                                    
                                        
                                    }
                                }
                               }
                          },
                          {
                            id: 'type_radius',name:'user_type',boxLabel:'模式2',value:'D',checked:editdata.data[0]['open_radius'],
                            listeners: 
                            {
                                check: function(radio,checked) 
                                {
                                    if(checked == true)
                                    {
                                        Ext.getCmp('local').hide();
                                        Ext.getCmp('radius').show();
                                        
                                    }
                                }
                               }
                          }
                     ]
                }


如何获得user_type 的值?其实是两个单选框 ;用Ext.getCmp("user_type").getValue() 不行;

------解决方案--------------------
加入以下代码
JScript code

Ext.override(Ext.form.RadioGroup, {   
    getValue: function(){   
        var v;   
        if (this.rendered) {   
            this.items.each(function(item){   
                if (!item.getValue())    
                    return true;   
                v = item.getRawValue();   
                return false;   
            });   
        }   
        else {   
            for (var k in this.items) {   
                if (this.items[k].checked) {   
                    v = this.items[k].inputValue;   
                    break;   
                }   
            }   
        }   
        return v;   
    },   
    setValue: function(v){   
        if (this.rendered)    
            this.items.each(function(item){   
                item.setValue(item.getRawValue() == v);   
            });   
        else {   
            for (var k in this.items) {   
                this.items[k].checked = this.items[k].inputValue == v;   
            }   
        }   
    }   
});

------解决方案--------------------
JScript code

var type;//结果
var typeObj = Ext.getCmp("ipmac_mod");
    if(typeObj){
    for(var i =0;i<2;i++){
          if(typeObj.items.items[i].checked){
        type = typeObj.items.items[i].inputValue;
          }
       }
      }

------解决方案--------------------
JScript code
var type_local=Ext.getCmp('type_local').getEl().dom
   ,type_radius=Ext.getCmp('type_radius').getEl().dom;
if(type_local.checked)alert(type_local.value);
else if(type_radius.checked)alert(type_radius.value);
else alert('没有选择!'); 
  相关解决方案