1.fieldset(checkbox) 获取值

复选框组件定义如下:

 1 {
 2                 xtype: \'fieldset\',
 3                 title: \'兴趣\',
 4                 autoHeight: true,
 5                 defaultType: \'checkbox\',
 6                 hideLabels: true,
 7                 id: \'xq\',
 8                 layout: \'hbox\',
 9                 defaults: {
10                     flex: 1
11                 },
12                 //vertical: false,
13                 items: [
14                     { boxLabel: \'游泳\', name: \'xqn\', inputValue: \'4\', checked: true },
15                     { boxLabel: \'玩儿\', name: \'xqn\', inputValue: \'5\' },
16                     { boxLabel: \'游戏\', name: \'xqn\', inputValue: \'6\' }
17                 ]
18 }

页面效果:

获取值代码:

1                     //获取通过fieldset定义的checkbox值 
2                     var xqCheck = Ext.getCmp(\'xq\').items;
3                     var xq = \'\';
4                     for(var i = 0; i < xqCheck.length; i++){
5                         if(xqCheck.get(i).checked){
6                             xq += \'+\' + xqCheck.get(i).boxLabel;
7                         }
8                     }
9                     Ext.MessageBox.alert(\'提示\', \'您的兴趣是\' + xq);

 

2.checkboxgroup 获取值

定义:

 1 {
 2                 xtype: \'checkboxgroup\',
 3                 fieldLabel: \'Hobby\',
 4                 id: \'hobby\',
 5                 columns: 2,
 6                 vertical: true,
 7                 items: [
 8                     { boxLabel: \'music\', name: \'rb\', inputValue: \'1\', checked: true },
 9                     { boxLabel: \'sport\', name: \'rb\', inputValue: \'2\' },
10                     { boxLabel: \'draw\', name: \'rb\', inputValue: \'3\' }
11                 ]
12 }

页面效果:

获取值:

1                     //获取通过checkboxgroup定义的checkbox值
2                     var hobbyValue = Ext.getCmp(\'hobby\').getChecked();
3                     var hobby;
4                     Ext.Array.each(hobbyValue, function(item){
5                         hobby += \'+\' + item.boxLabel;
6                     });
7                     Ext.MessageBox.alert(\'提示\', \'您的兴趣是\' + hobby);

 

版权声明:本文为lihuiyy原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/lihuiyy/archive/2012/08/20/2647144.html