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

76 lines
1.5 KiB
Markdown
Raw Normal View History

2017-03-28 11:56:38 +08:00
---
order: 2
title:
zh-CN: Radio.Group 组合 - 配置方式
en-US: Radio.Group group - optional
2017-03-28 11:56:38 +08:00
---
## 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 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',
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
2019-05-07 14:57:32 +08:00
onChange1 = e => {
2017-03-28 11:56:38 +08:00
console.log('radio1 checked', e.target.value);
this.setState({
value1: e.target.value,
});
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
2019-05-07 14:57:32 +08:00
onChange2 = e => {
2017-03-28 11:56:38 +08:00
console.log('radio2 checked', e.target.value);
this.setState({
value2: e.target.value,
});
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
2019-05-07 14:57:32 +08:00
onChange3 = e => {
2017-03-28 11:56:38 +08:00
console.log('radio3 checked', e.target.value);
this.setState({
value3: e.target.value,
});
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
2017-03-28 11:56:38 +08:00
render() {
return (
<div>
<Radio.Group options={plainOptions} onChange={this.onChange1} value={this.state.value1} />
<Radio.Group options={options} onChange={this.onChange2} value={this.state.value2} />
<Radio.Group
2019-05-07 14:57:32 +08:00
options={optionsWithDisabled}
onChange={this.onChange3}
value={this.state.value3}
/>
2017-03-28 11:56:38 +08:00
</div>
);
}
}
ReactDOM.render(<App />, mountNode);
2017-04-05 11:20:37 +08:00
```