提交 d60fca49 编写于 作者: Y yiminghe

fix datasource

上级 ed549a19
...@@ -56,7 +56,7 @@ var dataSource = new Table.DataSource({ ...@@ -56,7 +56,7 @@ var dataSource = new Table.DataSource({
sortField: sorter.field, sortField: sorter.field,
sortOrder: sorter.order sortOrder: sorter.order
}; };
for (let key in filters) { for (var key in filters) {
params[key] = filters[key]; params[key] = filters[key];
} }
console.log('请求参数:', params); console.log('请求参数:', params);
...@@ -64,14 +64,24 @@ var dataSource = new Table.DataSource({ ...@@ -64,14 +64,24 @@ var dataSource = new Table.DataSource({
} }
}); });
function fetch() { var Test=React.createClass({
dataSource.fetch().then(function() { getInitialState(){
console.log('fetch done'); 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> React.render(<Test />, document.getElementById('components-table-demo-ajax'));
<Table columns={columns} dataSource={dataSource} />
<button className="ant-btn ant-btn-primary" onClick={fetch}>外部重新加载数据</button>
</div>, document.getElementById('components-table-demo-ajax'));
```` ````
...@@ -16,13 +16,25 @@ function defaultResolve(data) { ...@@ -16,13 +16,25 @@ function defaultResolve(data) {
} }
class DataSource { class DataSource {
constructor(config) { init(config) {
this.config = config;
this.url = config.url || ''; this.url = config.url || '';
this.resolve = config.resolve || defaultResolve; this.resolve = config.resolve || defaultResolve;
this.getParams = config.getParams || noop; this.getParams = config.getParams || noop;
this.getPagination = config.getPagination || noop; this.getPagination = config.getPagination || noop;
this.headers = config.headers || {}; 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({ ...@@ -90,9 +102,7 @@ var AntTable = React.createClass({
}, },
getRemoteDataSource() { getRemoteDataSource() {
let dataSource = this.props.dataSource; return this.props.dataSource;
dataSource.fetch = this.fetch;
return dataSource;
}, },
toggleSortOrder(order, column) { toggleSortOrder(order, column) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册