2015-08-27 23:55:25 +08:00
|
|
|
# 外界控制数据
|
|
|
|
|
2015-10-09 17:14:09 +08:00
|
|
|
- order: 11
|
2015-08-27 23:55:25 +08:00
|
|
|
|
|
|
|
由父元素控制自身数据展示。
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
````jsx
|
2015-10-28 20:55:49 +08:00
|
|
|
import { Table, Button } from 'antd';
|
2015-10-08 15:13:04 +08:00
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const columns = [{
|
2015-08-27 23:55:25 +08:00
|
|
|
title: '姓名',
|
|
|
|
dataIndex: 'name',
|
|
|
|
render: function(text) {
|
2015-11-25 17:35:49 +08:00
|
|
|
return <a href="#">{text}</a>;
|
2015-08-27 23:55:25 +08:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
title: '年龄',
|
|
|
|
dataIndex: 'age'
|
|
|
|
}, {
|
|
|
|
title: '住址',
|
|
|
|
dataIndex: 'address'
|
|
|
|
}];
|
2015-10-28 20:55:49 +08:00
|
|
|
const data1 = [{
|
2015-08-28 15:22:09 +08:00
|
|
|
key: '1',
|
2015-08-27 23:55:25 +08:00
|
|
|
name: '胡彦斌',
|
|
|
|
age: 32,
|
|
|
|
address: '西湖区湖底公园1号'
|
|
|
|
}, {
|
2015-08-28 15:22:09 +08:00
|
|
|
key: '2',
|
2015-08-27 23:55:25 +08:00
|
|
|
name: '胡彦祖',
|
|
|
|
age: 42,
|
|
|
|
address: '西湖区湖底公园1号'
|
|
|
|
}, {
|
2015-08-28 15:22:09 +08:00
|
|
|
key: '3',
|
2015-08-27 23:55:25 +08:00
|
|
|
name: '李大嘴',
|
|
|
|
age: 32,
|
|
|
|
address: '西湖区湖底公园1号'
|
|
|
|
}];
|
2015-10-28 20:55:49 +08:00
|
|
|
const data2 = [{
|
2015-08-28 15:22:09 +08:00
|
|
|
key: '11',
|
2015-08-27 23:55:25 +08:00
|
|
|
name: '胡彦斌2',
|
|
|
|
age: 32,
|
|
|
|
address: '西湖区湖底公园2号'
|
|
|
|
}, {
|
2015-08-28 15:22:09 +08:00
|
|
|
key: '22',
|
2015-08-27 23:55:25 +08:00
|
|
|
name: '胡彦祖2',
|
|
|
|
age: 42,
|
|
|
|
address: '西湖区湖底公园2号'
|
|
|
|
}, {
|
2015-08-28 15:22:09 +08:00
|
|
|
key: '33',
|
2015-08-27 23:55:25 +08:00
|
|
|
name: '李大嘴2',
|
|
|
|
age: 32,
|
|
|
|
address: '西湖区湖底公园2号'
|
|
|
|
}];
|
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const App = React.createClass({
|
2015-08-27 23:55:25 +08:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
data: []
|
|
|
|
};
|
|
|
|
},
|
|
|
|
handleClick1() {
|
|
|
|
this.setState({
|
|
|
|
data: data1
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleClick2() {
|
|
|
|
this.setState({
|
|
|
|
data: data2
|
|
|
|
});
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return <div>
|
|
|
|
<Table columns={columns} dataSource={this.state.data} />
|
2015-10-08 15:13:04 +08:00
|
|
|
<Button onClick={this.handleClick1}>加载本地数据1</Button>
|
2015-08-27 23:55:25 +08:00
|
|
|
|
2015-10-08 15:13:04 +08:00
|
|
|
<Button onClick={this.handleClick2}>加载本地数据2</Button>
|
2015-08-27 23:55:25 +08:00
|
|
|
</div>;
|
|
|
|
}
|
2015-11-25 17:35:49 +08:00
|
|
|
});
|
2015-08-27 23:55:25 +08:00
|
|
|
|
2015-10-20 16:47:55 +08:00
|
|
|
ReactDOM.render(<App />
|
2015-08-27 23:55:25 +08:00
|
|
|
, document.getElementById('components-table-demo-local-data'));
|
|
|
|
````
|