ExtJs4新发现10_获取复选框(checkboxgroup&checkbox)的值


1.fieldset(checkbox) 获取值

复选框组件定义如下:

{
xtype: 'fieldset',
title: '兴趣',
autoHeight: true,
defaultType: 'checkbox',
hideLabels: true,
id: 'xq',
layout: 'hbox',
defaults: {
flex: 1
},
//vertical: false,
items: [
{ boxLabel: '游泳', name: 'xqn', inputValue: '4', checked: true },
{ boxLabel: '玩儿', name: 'xqn', inputValue: '5' },
{ boxLabel: '游戏', name: 'xqn', inputValue: '6' }
]
}

获取值代码:

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

2.checkboxgroup 获取值

{
xtype: 'checkboxgroup',
fieldLabel: 'Hobby',
id: 'hobby',
columns: 2,
vertical: true,
items: [
{ boxLabel: 'music', name: 'rb', inputValue: '1', checked: true },
{ boxLabel: 'sport', name: 'rb', inputValue: '2' },
{ boxLabel: 'draw', name: 'rb', inputValue: '3' }
]
}

获取值:

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

作者: middlekingt
原文: http://blog.csdn.net/middlekingt/article/details/8250672