ant-design/components/checkbox/demo/group.md

46 lines
1.0 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 3
2016-08-18 11:22:55 +08:00
title:
zh-CN: Checkbox 组
en-US: Checkbox Group
2016-03-31 09:40:55 +08:00
---
2015-12-24 15:03:06 +08:00
2016-08-18 11:22:55 +08:00
## zh-CN
方便的从数组生成 Checkbox 组。
2015-12-24 15:03:06 +08:00
2016-08-18 11:22:55 +08:00
## en-US
Generate a group of checkboxes from an array.
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);
}
const plainOptions = ['Apple', 'Pear', 'Orange'];
const options = [
2016-08-18 11:22:55 +08:00
{ label: 'Apple', value: 'Apple' },
{ label: 'Pear', value: 'Pear' },
{ label: 'Orange', value: 'Orange' },
];
const optionsWithDisabled = [
2016-08-18 11:22:55 +08:00
{ label: 'Apple', value: 'Apple' },
{ label: 'Pear', value: 'Pear' },
{ label: 'Orange', value: 'Orange', disabled: false },
];
ReactDOM.render(
<div>
<CheckboxGroup options={plainOptions} defaultValue={['Apple']} onChange={onChange} />
<br />
<CheckboxGroup options={options} defaultValue={['Pear']} onChange={onChange} />
<br />
<CheckboxGroup options={optionsWithDisabled} disabled defaultValue={['Apple']} onChange={onChange} />
</div>
, mountNode);
2015-12-24 15:03:06 +08:00
````