diff --git a/components/table/demo/ajax.md b/components/table/demo/ajax.md
index 445e60bb44..3fb3e12909 100644
--- a/components/table/demo/ajax.md
+++ b/components/table/demo/ajax.md
@@ -56,7 +56,7 @@ var dataSource = new Table.DataSource({
sortField: sorter.field,
sortOrder: sorter.order
};
- for (let key in filters) {
+ for (var key in filters) {
params[key] = filters[key];
}
console.log('请求参数:', params);
@@ -64,14 +64,24 @@ var dataSource = new Table.DataSource({
}
});
-function fetch() {
- dataSource.fetch().then(function() {
- console.log('fetch done');
- });
-}
+var Test=React.createClass({
+ getInitialState(){
+ return {
+ dataSource:dataSource
+ };
+ },
+ refresh(){
+ this.setState({
+ dataSource: this.state.dataSource.clone()
+ });
+ },
+ render(){
+ return
;
+ }
+});
-React.render(, document.getElementById('components-table-demo-ajax'));
+React.render(, document.getElementById('components-table-demo-ajax'));
````
diff --git a/components/table/index.jsx b/components/table/index.jsx
index 6b9e526046..977e2a8c2f 100644
--- a/components/table/index.jsx
+++ b/components/table/index.jsx
@@ -16,13 +16,25 @@ function defaultResolve(data) {
}
class DataSource {
- constructor(config) {
+ init(config) {
+ this.config = config;
this.url = config.url || '';
this.resolve = config.resolve || defaultResolve;
this.getParams = config.getParams || noop;
this.getPagination = config.getPagination || noop;
this.headers = config.headers || {};
- this.fetch = noop;
+ }
+
+ constructor(config) {
+ if (config) {
+ this.init(config);
+ }
+ }
+
+ clone() {
+ var d = new DataSource();
+ d.init(this.config);
+ return d;
}
}
@@ -90,9 +102,7 @@ var AntTable = React.createClass({
},
getRemoteDataSource() {
- let dataSource = this.props.dataSource;
- dataSource.fetch = this.fetch;
- return dataSource;
+ return this.props.dataSource;
},
toggleSortOrder(order, column) {