提交 d60fca49 编写于 作者: Y yiminghe

fix datasource

上级 ed549a19
......@@ -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 <div>
<Table columns={columns} dataSource={this.state.dataSource} />
<button className="ant-btn ant-btn-primary" onClick={this.refresh}>外部重新加载数据</button>
</div>;
}
});
React.render(<div>
<Table columns={columns} dataSource={dataSource} />
<button className="ant-btn ant-btn-primary" onClick={fetch}>外部重新加载数据</button>
</div>, document.getElementById('components-table-demo-ajax'));
React.render(<Test />, document.getElementById('components-table-demo-ajax'));
````
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册