【问题标题】:how to build a pagination for the API api.rawg.io如何为 API api.rawg.io 构建分页
【发布时间】:2021-03-24 13:55:57
【问题描述】:

我正在尝试为此 API https://api.rawg.io/docs/#tag/games 构建分页

在此页面中,他们解释了 API 返回的参数 https://rawgthedocs.orels.sh/api/#basics

我的http请求return this.http.get('https://api.rawg.io/api/games?dates=2010-01-01,2020-12-31&page_size=20&page=3');

在我的角度组件中,我得到了数据

constructor(
    private gamesService:GamesService,
    private router: Router,
  ) {
    this.gamesService.getListGames().subscribe( (data: any) =>{
      console.log(data.results);
      this.gameslist = data.results;
      this.count = data.results.length;
      console.log(this.count);

      if(data.results.page == 3)
      {
        
      }    

     });

我不知道如何获取请求中为 &page=3 的页面参数以及构建分页的 next 和 prev 参数

【问题讨论】:

    标签: angular api pagination


    【解决方案1】:

    在这里,首先您必须收集 data.nextdata.previous 网址,然后使用这些链接进行下一个或上一个分页。

    要使用dates参数,创建HttpParams的对象-

    let params = new HttpParams();
    params = params.append('dates','2010-01-01,2020-12-31');
    

    最后将它们添加到您的 gamesService.getListGames() http 函数中

    this.http.get(url, {params: this.params});
    

    其中params 是上面创建的HttpParams 对象。

    【讨论】:

      猜你喜欢
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多