ajax.md 795 字节
Newer Older
A
afc163 已提交
1 2
# 动态加载数据

3
- order: 7
A
afc163 已提交
4

A
afc163 已提交
5
`dataSource="/api/data.json"`,列表数据是远程读取的,并有 loading 效果。
A
afc163 已提交
6 7 8 9

---

````jsx
A
afc163 已提交
10 11 12 13 14 15 16 17 18 19 20 21
var Table = antd.Table;
var columns = [{
  title: '姓名',
  dataIndex: 'name'
}, {
  title: '年龄',
  dataIndex: 'age'
}, {
  title: '住址',
  dataIndex: 'address'
}];

A
afc163 已提交
22 23 24 25
function resolve(result) {
  return result.data;
}

26 27 28 29
var dataSource = {
  url: "/components/table/demo/data.json",
  resolve: function(result) {
    return result.data;
A
afc163 已提交
30 31 32 33 34 35 36
  },
  // 和后台接口返回的分页数据进行适配
  getPagination: function(result) {
    return {
      total: result.totalCount,
      pageSize: result.pageSize
    }
37 38 39 40
  }
};

React.render(<Table columns={columns} dataSource={dataSource} />
A
afc163 已提交
41
, document.getElementById('components-table-demo-ajax'));
A
afc163 已提交
42
````