fix datasource

This commit is contained in:
yiminghe 2015-08-07 01:03:42 +08:00
parent ed549a19b3
commit d60fca4993
2 changed files with 35 additions and 15 deletions

View File

@ -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'));
````

View File

@ -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) {