2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 3
|
|
|
|
title: Checkbox 组
|
|
|
|
---
|
2015-12-24 15:03:06 +08:00
|
|
|
|
2016-03-09 21:08:08 +08:00
|
|
|
方便的从数组生成 Checkbox 组。
|
2015-12-24 15:03:06 +08:00
|
|
|
|
|
|
|
````jsx
|
|
|
|
import { Checkbox } from 'antd';
|
2015-12-24 15:13:23 +08:00
|
|
|
const CheckboxGroup = Checkbox.Group;
|
2015-12-24 15:03:06 +08:00
|
|
|
|
|
|
|
function onChange(checkedValues) {
|
|
|
|
console.log('checked = ', checkedValues);
|
|
|
|
}
|
|
|
|
|
2016-03-09 21:08:08 +08:00
|
|
|
const plainOptions = ['Apple', 'Pear', 'Orange'];
|
|
|
|
const options = [{
|
|
|
|
label: '苹果',
|
|
|
|
value: 'Apple',
|
|
|
|
}, {
|
|
|
|
label: '梨',
|
|
|
|
value: 'Pear',
|
|
|
|
}, {
|
|
|
|
label: '橘',
|
|
|
|
value: 'Orange',
|
|
|
|
}];
|
2016-03-17 11:10:58 +08:00
|
|
|
const optionsWithDisabled = [
|
|
|
|
{ label: '苹果', value: 'Apple' },
|
|
|
|
{ label: '梨', value: 'Pear' },
|
|
|
|
{ label: '橘', value: 'Orange', disabled: false },
|
|
|
|
];
|
2016-03-09 21:08:08 +08:00
|
|
|
|
2015-12-25 11:42:13 +08:00
|
|
|
ReactDOM.render(
|
2016-03-09 21:08:08 +08:00
|
|
|
<div>
|
|
|
|
<CheckboxGroup options={plainOptions} defaultValue={['Apple']} onChange={onChange} />
|
|
|
|
<br />
|
|
|
|
<CheckboxGroup options={options} defaultValue={['Pear']} onChange={onChange} />
|
2016-03-17 11:10:58 +08:00
|
|
|
<br />
|
|
|
|
<CheckboxGroup options={optionsWithDisabled} disabled defaultValue={['Apple']} onChange={onChange} />
|
2016-03-09 21:08:08 +08:00
|
|
|
</div>
|
2015-12-29 12:08:58 +08:00
|
|
|
, mountNode);
|
2015-12-24 15:03:06 +08:00
|
|
|
````
|