【问题标题】:React Infinite scrolling with using API使用 API 反应无限滚动
【发布时间】:2018-08-05 16:03:04
【问题描述】:

我想使用 yts API 以无限滚动的方式显示每 10 个数据。 它表明我可以通过此代码显示数据https://yts.am/api/v2/list_movies.json?sort_by=download_count&limit=10' 它的限制在 1 - 50 之间,但我想无限显示数据。似乎有页面参数.. 你们知道如何无限显示数据吗?

这是 yts API 的链接 https://yts.am/api#list_movies

这是我的调用 API 代码

_getMovies = async()=>{
 const movies = await this._callApi() 
 this.setState({
   movies 
 })
}

  _callApi=()=>{
    return   fetch('https://yts.am/api/v2/list_movies.json?sort_by=download_count&limit=10')
    .then(potato=> potato.json()) 
    .then(json=> json.data.movies)
    .catch(err=>console.log(err))
    }

【问题讨论】:

    标签: reactjs infinite-scroll


    【解决方案1】:

    infinite scoll 背后的基本思想是从 API 中获取 N 条记录。 N 取决于您的屏幕高度,因此您的列表中的每个项目都会有一些高度,因此划分每个项目的可用屏幕高度/高度。现在它将在 N 中为您提供一些数字,现在需要一些额外的记录,例如 4-5 以便您可以滚动,现在检查 scrollTop 是否超过了 scrollHeight 属性。当它再次调用下一页时。就是这样,这就是它的工作原理。

    【讨论】:

      猜你喜欢
      • 2020-05-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-06
      • 2017-08-02
      • 2021-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多