mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-25 11:40:04 +08:00
fix datasource
This commit is contained in:
parent
ed549a19b3
commit
d60fca4993
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user