ant-design/components/checkbox/demo/controller.md

62 lines
1.4 KiB
Markdown
Raw Normal View History

2015-07-16 14:34:42 +08:00
# 和外部组件通信
2015-07-15 15:19:24 +08:00
- order: 2
联动 checkbox。
---
````jsx
var Checkbox = antd.Checkbox;
var Button = antd.Button;
2015-07-15 15:19:24 +08:00
var container = document.getElementById('components-checkbox-demo-controller');
var App = React.createClass({
2015-07-16 14:34:42 +08:00
getInitialState() {
return {
checked: true,
disabled: false
2015-07-15 15:19:24 +08:00
}
2015-07-16 14:34:42 +08:00
},
render() {
var label = (this.state.checked ? '选中' : '取消') + '-' +
(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>
<Button type="primary" size="sm"
2015-07-16 14:34:42 +08:00
onClick={this.toggleChecked}>
{!this.state.checked ? "选中":"取消"}
</Button>
<Button style={{'marginLeft': '10px'}}
type="primary" size="sm"
2015-07-16 14:34:42 +08:00
onClick={this.toggleDisable}>
{!this.state.disabled ? "不可用":"可用"}
</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-10-20 16:47:55 +08:00
ReactDOM.render(<App />, container);
2015-07-15 15:19:24 +08:00
````