+ -
当前位置:首页 → 问答吧 → Ext 如何获取radio的值?

Ext 如何获取radio的值?

时间:2011-06-29

来源:互联网

有如下代码:
{
  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() 不行;

作者: shrimpma   发布时间: 2011-06-29

加入以下代码
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;   
            }   
        }   
    }   
});


在页面提交表单时就有值了

作者: sainer   发布时间: 2011-06-29