2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 3
|
2016-08-18 11:22:55 +08:00
|
|
|
title:
|
2019-05-07 14:57:32 +08:00
|
|
|
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
|
|
|
|
|
2016-03-09 21:08:08 +08:00
|
|
|
方便的从数组生成 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.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2015-12-24 15:03:06 +08:00
|
|
|
import { Checkbox } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
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'];
|
2016-05-11 11:30:10 +08:00
|
|
|
const options = [
|
2016-08-18 11:22:55 +08:00
|
|
|
{ label: 'Apple', value: 'Apple' },
|
|
|
|
{ label: 'Pear', value: 'Pear' },
|
|
|
|
{ label: 'Orange', value: 'Orange' },
|
2016-05-11 11:30:10 +08:00
|
|
|
];
|
2016-03-17 11:10:58 +08:00
|
|
|
const optionsWithDisabled = [
|
2016-08-18 11:22:55 +08:00
|
|
|
{ label: 'Apple', value: 'Apple' },
|
|
|
|
{ label: 'Pear', value: 'Pear' },
|
|
|
|
{ label: 'Orange', value: 'Orange', disabled: false },
|
2016-03-17 11:10:58 +08:00
|
|
|
];
|
2016-03-09 21:08:08 +08:00
|
|
|
|
2015-12-25 11:42:13 +08:00
|
|
|
ReactDOM.render(
|
2016-04-29 12:13:27 +08:00
|
|
|
<div>
|
2019-05-27 21:32:45 +08:00
|
|
|
<Checkbox.Group options={plainOptions} defaultValue={['Apple']} onChange={onChange} />
|
2019-05-07 14:57:32 +08:00
|
|
|
<br />
|
|
|
|
<br />
|
2019-05-27 21:32:45 +08:00
|
|
|
<Checkbox.Group options={options} defaultValue={['Pear']} onChange={onChange} />
|
2019-05-07 14:57:32 +08:00
|
|
|
<br />
|
|
|
|
<br />
|
2019-05-27 21:32:45 +08:00
|
|
|
<Checkbox.Group
|
2019-05-07 14:57:32 +08:00
|
|
|
options={optionsWithDisabled}
|
|
|
|
disabled
|
|
|
|
defaultValue={['Apple']}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
2018-06-27 15:55:04 +08:00
|
|
|
</div>,
|
2019-05-07 14:57:32 +08:00
|
|
|
mountNode,
|
2018-11-28 15:00:03 +08:00
|
|
|
);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|