You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB

# 和外部组件通信
10 years ago
- order: 2
联动 checkbox。
---
````jsx
var Checkbox = antd.Checkbox;
var container = document.getElementById('components-checkbox-demo-controller');
var App = React.createClass({
getInitialState() {
return {
checked: true,
disabled: false
10 years ago
}
},
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}
onChange={this.onChange} />
{label}
</label>
</p>
<p>
<button className="ant-btn ant-btn-primary ant-btn-sm"
onClick={this.toggleChecked}>
{!this.state.checked ? "选中":"取消"}
</button>
<button style={{'marginLeft': '10px'}}
className="ant-btn ant-btn-primary ant-btn-sm"
onClick={this.toggleDisable}>
{!this.state.disabled ? "不可用":"可用"}
</button>
</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);
this.setState({
checked: e.target.checked
});
}
10 years ago
});
React.render(<App />, container);
````