如何从响应体获取后端的Angular 排序列表?

6g8kf2rb  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(207)

我想用排序条件在请求正文中发布如下内容:

{
  "page": {
    "number": 0,
    "size": 10
  },
  "searchSortCriteria": [
    {
      "key": "id",
      "operation": "ASC"
    }
  ]
}

后端从响应主体返回已排序的费用列表,如下所示:

{
  "page": null,
  "hasNextPage": false,
  "totalPages": 1,
  "expenses": [
    {
      "createdUser": null,
      "updatedUser": null,
      "createdDate": "2021-07-11T19:50:23",
      "updatedDate": null,
      "id": 4,
      "user": "Radek",
      "amount": 123,
      "currency": "PLN",
      "description": "Grocery",
      "payDate": "2021-07-11",
      "payMethod": {
        "id": 2,
        "payMethodName": "Cash"
      },
      "expenseCategory": {
        "id": 1,
        "categoryName": "Food at home"
      }
    },
    {
      "createdUser": null,
      "updatedUser": null,
      "createdDate": "2021-07-11T19:53:00",
      "updatedDate": null,
      "id": 5,
      "user": "Agata",
      "amount": 52,
      "currency": "PLN",
      "description": "toys",
      "payDate": "2021-07-10",
      "payMethod": {
        "id": 1,
        "payMethodName": "Credit card"
      },
      "expenseCategory": {
        "id": 11,
        "categoryName": "Other"
      }
    }
  ]
}

我知道如何提出适当的请求,但我有一个问题,如何从响应体获得排序列表。我正在寻找任何可以从响应体中的json中提取的方法。

public findAllPost(criteriaRequest: ExpenseCriteriaRequest): Observable<ExpenseCriteriaRequest> {
    return this.httpClient.post<ExpenseCriteriaRequest>(this.url, criteriaRequest, this.httpOptions);
  }
ngOnInit(): void {
    this.expenseService.findAllPost(this.criteriaRequest)
      .subscribe(request => this.criteriaRequest = request);
  }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题