【问题标题】:How to set count of JSON data from API to allow that many on a list?如何设置来自 API 的 JSON 数据计数以允许列表中的那么多?
【发布时间】:2018-08-27 13:42:43
【问题描述】:
export default class FutureLaunches extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isLoading: true,
      dataSource: null
    };
  }

  componentDidMount() {
    return fetch("https://launchlibrary.net/1.4/launch")
      .then(response => response.json())
      .then(responseJson => {
        this.setState({
          isLoading: false,
          dataSource: responseJson.launches
        });
      })
      .catch(error => {
        console.log(error);
      });
  }

  render() {
    if (this.state.isLoading) {
      return (
        <View style={styles.container}>
          <ActivityIndicator />
        </View>
      );
    } else {
      let launches = this.state.dataSource.map((val, key) => {
        return (
          <View key={key}>
            <Text style={styles.name}>{val.name}</Text>
            <Text>{val.net}</Text>
            <Text>{val.windowstart}</Text>
            <Text>{val.windowend}</Text>
            <Text>{val.count}</Text>
          </View>
        );
      });

      return (
        <View style={styles.container}>
          <ScrollView contentContainerStyle={styles.contentContainer}>
            {launches}
          </ScrollView>
        </View>
      );
    }
  }
}

});

json中的total高于count,count显示页面上数据集的数量。我怎样才能更改 json 上的计数,以便它可以允许来自 https://launchlibrary.net/1.4/launch 的所有数据集,在这种情况下,有 183 个数据集可用。

【问题讨论】:

  • 根据doc 注意:响应中的总数是满足您的标准的启动总数,用于分页。您可以通过更改偏移量来获取下一页。
  • 如何更改偏移量?

标签: javascript api react-native count fetch


【解决方案1】:

根据文档,有一个limit 参数控制页面大小。将该 URL 中的参数设置为 -1 会返回所有结果:

https://launchlibrary.net/1.4/launch?limit=-1

【讨论】:

  • 是的!每次启动都会在物理上加载......谢谢你必须查看获取细节所需的其他参数
猜你喜欢
  • 2015-06-20
  • 1970-01-01
  • 1970-01-01
  • 2018-07-01
  • 2011-01-14
  • 1970-01-01
  • 2017-02-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多