This commit is contained in:
simaQ 2015-07-16 15:26:03 +08:00
commit 403149f2a1
3 changed files with 53 additions and 51 deletions

View File

@ -1,4 +1,4 @@
# 基本用法
# 和外部组件通信
- order: 2
@ -8,46 +8,51 @@
````jsx
var Checkbox = antd.Checkbox;
var container = document.getElementById('components-checkbox-demo-controller');
var App = React.createClass({
getInitialState(){
return {
checked:true,
disabled:false
}
},
render(){
var label = (this.state.checked ? "选中":"取消") + "-" + (this.state.disabled ? "不可用":"可用");
return <ul>
<li>
<label><Checkbox checked={this.state.checked} disabled={this.state.disabled} onChange={this.onChange}/>
{label}
</label>
</li>
<li>
<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>
</li>
</ul>;
},
toggleChecked(e){
this.setState({checked:!this.state.checked});
},
toggleDisable(e){
this.setState({disabled:!this.state.disabled});
},
onChange(checked){
console.log('checked = ',e.target.checked);
getInitialState() {
return {
checked: true,
disabled: false
}
},
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
});
}
});
React.render(<App />, container);

View File

@ -2,7 +2,7 @@
- order: 1
checkbox 不可用
checkbox 不可用
---
@ -10,14 +10,9 @@ checkbox 不可用
var Checkbox = antd.Checkbox;
var container = document.getElementById('components-checkbox-demo-disable');
React.render(
<ul>
<li>
<Checkbox defaultChecked={false} disabled={true}/>
</li>
<li>
<Checkbox defaultChecked={true} disabled={true}/>
</li>
</ul>
, container);
React.render(<div>
<Checkbox defaultChecked={false} disabled={true}/>
<br />
<Checkbox defaultChecked={true} disabled={true}/>
</div>, container);
````

View File

@ -103,7 +103,8 @@ let AntTable = React.createClass({
}
this.fetch();
},
handleSelect(rowIndex, checked) {
handleSelect(rowIndex, e) {
let checked = e.target.checked;
if (checked) {
this.state.selectedRowKeys.push(rowIndex);
} else {
@ -122,8 +123,9 @@ let AntTable = React.createClass({
this.props.rowSelection.onSelect(currentRow, checked, selectedRows);
}
},
handleSelectAllRow(checked) {
var selectedRowKeys = checked ? this.state.data.map(function(item, i) {
handleSelectAllRow(e) {
let checked = e.target.checked;
let selectedRowKeys = checked ? this.state.data.map(function(item, i) {
return i + 1;
}) : [];
this.setState({