2015-07-16 14:34:42 +08:00
|
|
|
# 和外部组件通信
|
2015-07-15 15:19:24 +08:00
|
|
|
|
|
|
|
- order: 2
|
|
|
|
|
|
|
|
联动 checkbox。
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
````jsx
|
2015-10-28 20:55:49 +08:00
|
|
|
import { Checkbox, Button } from 'antd';
|
2015-07-15 15:19:24 +08:00
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const App = React.createClass({
|
2015-07-16 14:34:42 +08:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
checked: true,
|
|
|
|
disabled: false
|
2015-10-28 20:55:49 +08:00
|
|
|
};
|
2015-07-16 14:34:42 +08:00
|
|
|
},
|
|
|
|
render() {
|
2015-11-25 17:35:49 +08:00
|
|
|
const label = (this.state.checked ? '选中' : '取消') + '-' +
|
2015-07-16 14:34:42 +08:00
|
|
|
(this.state.disabled ? '不可用' : '可用');
|
|
|
|
return <div>
|
|
|
|
<p style={{marginBottom: '20px'}}>
|
|
|
|
<label>
|
|
|
|
<Checkbox checked={this.state.checked}
|
|
|
|
disabled={this.state.disabled}
|
2015-07-17 11:06:38 +08:00
|
|
|
onChange={this.onChange} />
|
|
|
|
{label}
|
2015-07-16 14:34:42 +08:00
|
|
|
</label>
|
|
|
|
</p>
|
|
|
|
<p>
|
2015-10-26 11:02:48 +08:00
|
|
|
<Button type="primary" size="small"
|
2015-07-16 14:34:42 +08:00
|
|
|
onClick={this.toggleChecked}>
|
2015-11-25 17:35:49 +08:00
|
|
|
{!this.state.checked ? '选中' : '取消'}
|
2015-10-08 15:13:04 +08:00
|
|
|
</Button>
|
2015-11-25 17:35:49 +08:00
|
|
|
<Button style={{marginLeft: '10px'}}
|
2015-10-26 11:02:48 +08:00
|
|
|
type="primary" size="small"
|
2015-07-16 14:34:42 +08:00
|
|
|
onClick={this.toggleDisable}>
|
2015-11-25 17:35:49 +08:00
|
|
|
{!this.state.disabled ? '不可用' : '可用'}
|
2015-10-08 15:13:04 +08:00
|
|
|
</Button>
|
2015-07-16 14:34:42 +08:00
|
|
|
</p>
|
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
toggleChecked(e) {
|
|
|
|
this.setState({checked: !this.state.checked});
|
|
|
|
},
|
|
|
|
toggleDisable(e) {
|
|
|
|
this.setState({disabled: !this.state.disabled});
|
|
|
|
},
|
|
|
|
onChange(e) {
|
|
|
|
console.log('checked = ', e.target.checked);
|
2015-07-16 14:48:57 +08:00
|
|
|
this.setState({
|
|
|
|
checked: e.target.checked
|
|
|
|
});
|
2015-07-16 14:34:42 +08:00
|
|
|
}
|
2015-07-15 15:19:24 +08:00
|
|
|
});
|
|
|
|
|
2015-12-16 15:25:15 +08:00
|
|
|
ReactDOM.render(<App />, document.getElementById('components-checkbox-demo-controller'));
|
2015-07-15 15:19:24 +08:00
|
|
|
````
|