ExtJS 获取单选按钮的值 radiogroup 获取值 fieldset(radio) 获取值

 1 {
 2                 xtype: 'fieldset',
 3                 id: 'job',
 4                 title: '职业',
 5                 autoHeight: true,
 6                 defaultType: 'radio',  //设置fieldset内的默认元素为radio
 7                 //hideLabel: false,
 8                 layout: 'hbox',
 9                 defaults: {
10                     flex: 1
11                 },
12                 items: [
13                     { boxLabel: '学生', name: 'job', inputValue: '1', checked: true },
14                     { boxLabel: '教师', name: 'job', inputValue: '2' },
15                     { boxLabel: '其他', name: 'job', inputValue: '3' }
16                 ]
17 }

如果是以上定义,则页面效果为:

通过以下语句中变量 job 保存的是选中的标签值(学生、教师、其他)

 1                     var jobRadio = Ext.getCmp('job').items;
 2                     var jobValue = loginForm.getForm().findField("job").getGroupValue(); //此处获取到的是inputValue的值
 3                     var job;
 4                     for(var i = 0; i < jobRadio.length; i++){
 5                         if(jobRadio.get(i).inputValue == jobValue){
 6                             job = jobRadio.get(i).boxLabel;
 7                             break;
 8                         }
 9                     }
10                     Ext.MessageBox.alert('提示', '您的职业是' + job);

 

以上是通过 fieldset 定义的 radio 组件获取值的方法。下面是 radiogroup 组件获取值的方法

 1 {
 2                 //xtype      : 'fieldcontainer',
 3                 xtype: 'radiogroup',
 4                 id: 'sex',
 5                 fieldLabel : 'Sex',
 6                 hideLabels: false,
 7                 defaults: {
 8                     flex: 1
 9                 },
10                 layout: 'hbox',
11                 items: [
12                     {
13                         boxLabel  : 'Male',
14                         name      : 'sex',
15                         inputValue: 'male'
16                     }, {
17                         boxLabel  : 'Female',
18                            name      : 'sex',
19                         inputValue: 'female'
20                     }
21                 ]
22             }

页面效果为:

获取值的代码如下:

1                     var sex = Ext.getCmp('sex').getChecked()[0].boxLabel;
2                     Ext.MessageBox.alert('提示', '您的性别是' + sex);

 

posted @ 2012-08-16 13:58  lihui_yy  阅读(20987)  评论(0编辑  收藏  举报