我在使用DataSource进行Material Pagination时遇到了麻烦.我需要从服务中返回REST服务提供的整理项目(我无法更改).到目前为止,我能做到的唯一方法是两次做同样的请求,这是不对的.
如果查看"servers-collection.component.ts",我只需调用"getServiceData"来获取分页的总项目(请求响应中的"total_items").我正在寻找的是直接从主要请求获取数据.
这是我的原始响应(GET):
{
"_links": {
"self": {
"href": "https://{URL}/servers?page=1"
},
"first": {
"href": "http://{URL}/servers"
},
"last": {
"href": "http://{URL}/servers?page=100"
},
"next": {
"href": "http://{URL}/servers?page=2"
}
},
"_embedded": {
"servers": [
{
"id": 1,
"name": "Server Name",
"ipAddress": "111.222.333.444",
"hostName": "server.hostname.com",
"_links": {
"self": {
"href": "http://{URL}/servers/1"
}
}
}
]
},
"page_count": 100,
"page_size": 5,
"total_items": 498,
"page": 1
}
Run Code Online (Sandbox Code Playgroud)
......这就是我做的事情:
服务器 - collection.component.html
<div class="example-container mat-elevation-z8">
<mat-table #table [dataSource]="dataSource">
<!-- ID Column -->
<ng-container matColumnDef="id">
<mat-header-cell *matHeaderCellDef> …
Run Code Online (Sandbox Code Playgroud)