ExtJS 獲取復選框的值 checkboxgroup 獲取值 fieldset(checkbox) 獲取值


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM