ant-design/components/radio/demo/radiogroup-options.md

74 lines
1.5 KiB
Markdown
Raw Normal View History

2017-03-28 11:56:38 +08:00
---
order: 2
title:
zh-CN: RadioGroup 组合 - 配置方式
en-US: RadioGroup group - optional
---
## zh-CN
2017-04-05 11:20:37 +08:00
通过配置 `options` 参数来渲染单选框。
2017-03-28 11:56:38 +08:00
## en-US
2017-04-05 11:20:37 +08:00
Render radios by configuring `options`.
2017-03-28 11:56:38 +08:00
```jsx
import { Radio } from 'antd';
2018-06-27 15:55:04 +08:00
2017-03-28 11:56:38 +08:00
const RadioGroup = Radio.Group;
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 },
];
class App extends React.Component {
state = {
value1: 'Apple',
value2: 'Apple',
value3: 'Apple',
}
2018-06-27 15:55:04 +08:00
2017-03-28 11:56:38 +08:00
onChange1 = (e) => {
console.log('radio1 checked', e.target.value);
this.setState({
value1: e.target.value,
});
}
2018-06-27 15:55:04 +08:00
2017-03-28 11:56:38 +08:00
onChange2 = (e) => {
console.log('radio2 checked', e.target.value);
this.setState({
value2: e.target.value,
});
}
2018-06-27 15:55:04 +08:00
2017-03-28 11:56:38 +08:00
onChange3 = (e) => {
console.log('radio3 checked', e.target.value);
this.setState({
value3: e.target.value,
});
}
2018-06-27 15:55:04 +08:00
2017-03-28 11:56:38 +08:00
render() {
return (
<div>
<RadioGroup options={plainOptions} onChange={this.onChange1} value={this.state.value1} />
<RadioGroup options={options} onChange={this.onChange2} value={this.state.value2} />
<RadioGroup options={optionsWithDisabled} onChange={this.onChange3} value={this.state.value3} />
</div>
);
}
}
ReactDOM.render(<App />, mountNode);
2017-04-05 11:20:37 +08:00
```