提交 ed9b0c50 编写于 作者: A afc163

load datasource in table, update API

上级 c6889fa2
......@@ -19,6 +19,10 @@ var columns = [{
dataIndex: 'address'
}];
React.render(<Table columns={columns} dataSource="/components/table/demo/data.json" />
function resolve(result) {
return result.data;
}
React.render(<Table columns={columns} dataSource="/components/table/demo/data.json" resolve={resolve} />
, document.getElementById('components-table-demo-ajax'));
````
[{
"name": "胡彦斌ajax",
"age": 32,
"address": "西湖区湖底公园1号"
}, {
"name": "胡彦祖ajax",
"age": 42,
"address": "西湖区湖底公园1号"
}, {
"name": "李大嘴ajax",
"age": 32,
"address": "西湖区湖底公园1号"
}]
{
"data": [{
"name": "胡彦斌ajax",
"age": 32,
"address": "西湖区湖底公园1号"
}, {
"name": "胡彦祖ajax",
"age": 42,
"address": "西湖区湖底公园1号"
}, {
"name": "李大嘴ajax",
"age": 32,
"address": "西湖区湖底公园1号"
}]
}
......@@ -55,6 +55,9 @@ let AntTable = React.createClass({
return checkbox;
},
loadData: function() {
this.props.resolve = this.props.resolve || function(data) {
return data || [];
};
if (this.props.dataSource) {
this.setState({
loading: true
......@@ -62,7 +65,7 @@ let AntTable = React.createClass({
jQuery.ajax({
url: this.props.dataSource,
success: (result) => {
result = result || [];
result = this.props.resolve.call(this, result);
if (this.isMounted()) {
this.setState({
data: result
......
......@@ -17,8 +17,10 @@
### Table
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---------------|-------------------------|---------------|--------------------|---------|
| rowSelection | 列表项是否可选择 | Object | | false |
| pagenation | 分页器 | React.Element | | |
| size | 正常或迷你类型 | string | `normal` or `mini` | normal |
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---------------|--------------------------|---------------|--------------------|---------|
| rowSelection | 列表项是否可选择 | Object | | false |
| pagenation | 分页器 | React.Element | | |
| size | 正常或迷你类型 | string | `normal` or `mini` | normal |
| dataSource | 数据源的 http 地址 | string | | |
| resolve | 将远程数据转换为表格数据 | function | | |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册