问题描述
我正在将ng2-smart-table与ServerDataSource一起使用
this.source = new ServerDataSource(_http,{
dataKey: 'data.data',endPoint: 'https://myapi?page=',pagerPageKey: 'data.Meta.current_page',pagerLimitKey: 'data.Meta.per_page',totalKey: 'data.Meta.total',});
在我的网址上我得到了这个http://localhost:4200/pages/admin/users-list?page=1
,但是即使我将网址更改为其他页面,在浏览页面时也不会更改。如果我将自己的api从https://myapi?page=1
更改为https://myapi?page=2
,就可以了,我知道我做错了什么,但是在哪里?
编辑
我不知道这是否行得通,但我认为我需要通过听页面更改事件来获取“当前页面”。所以现在我有了这段代码:
this.source.onChanged().subscribe((change) => {
if (change.action === 'page') {
this.page = change.paging.page;
this.userService.getAllUser(this.page).subscribe(
(data:any)=>console.log(data.data.data)
)
}
});
我得到了想要的结果,但是问题是如何使用this.page
到myapi?page=
。有人有解决方案吗?
编辑
this.source = new ServerDataSource(_http,endPoint: 'https://myapi',pagerPageKey: 'page',});
解决方法
我认为您需要在数据源配置对象中更改页面参数
this.source = new ServerDataSource(_http,{
dataKey: 'data.data',endPoint: 'https://myapi/endpoint',pagerPageKey: 'page',// this should be page number param name in endpoint (request not response) for example 'page'
pagerLimitKey: 'your-endpoint-param-name-for-pageSize',// this should page size param name in endpoint (request not response)
totalKey: 'data.meta.total',// this is total records count in response,key seems right
});
因此您需要将pagerPageKey值更改为'page',并将pagerpagelimit更改为端点中的键
无需处理this.source.onChanged()//删除此代码