mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-29 20:08:37 +08:00
47 lines
1.0 KiB
Markdown
47 lines
1.0 KiB
Markdown
---
|
|
order: 3
|
|
title:
|
|
zh-CN: Checkbox 组
|
|
en-US: Checkbox Group
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
方便的从数组生成 Checkbox 组。
|
|
|
|
## en-US
|
|
|
|
Generate a group of checkboxes from an array.
|
|
|
|
````jsx
|
|
import { Checkbox } from 'antd';
|
|
|
|
const CheckboxGroup = Checkbox.Group;
|
|
|
|
function onChange(checkedValues) {
|
|
console.log('checked = ', checkedValues);
|
|
}
|
|
|
|
const plainOptions = ['Apple', 'Pear', 'Orange'];
|
|
const options = [
|
|
{ label: 'Apple', value: 'Apple' },
|
|
{ label: 'Pear', value: 'Pear' },
|
|
{ label: 'Orange', value: 'Orange' },
|
|
];
|
|
const optionsWithDisabled = [
|
|
{ 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 /><br />
|
|
<CheckboxGroup options={options} defaultValue={['Pear']} onChange={onChange} />
|
|
<br /><br />
|
|
<CheckboxGroup options={optionsWithDisabled} disabled defaultValue={['Apple']} onChange={onChange} />
|
|
</div>,
|
|
mountNode);
|
|
````
|