【问题标题】:how to make click button in bootstrap and all data are come API如何在引导程序中制作点击按钮,所有数据都来自 API
【发布时间】:2020-08-09 14:19:25
【问题描述】:

反应
如果你可以看到下面的代码,当我点击真按钮或假按钮时,我会尝试制作,然后根据点击数据更改,所有数据都来自 API

_filterByLaunch = launch => {
    const post = this.state.allPosts.filter(item =>
    item.launch_success === launch
    );
    this.setState({ post });
    }

你可以在这里看到 API URL https://api.spaceXdata.com/v3/launches?limit=100&launch_success=true

Demo

【问题讨论】:

  • 当我点击真或假时,数据不显示,所有数据都来自 api,你可以在这里看到codepen.io/namratasep6/pen/JjXoxBv
  • 任何机构帮助我非常感谢
  • 为什么不工作??
  • 你看到我的回答了吗?

标签: reactjs


【解决方案1】:

调用 _filterByLaunch 时,传递布尔类型 truefalse 而不是字符串 'true''false'。响应中的数据类型是布尔类型。

launch_success: true //NOT launch_success: 'true'

所以使用_filterByLaunch(true),而不是_filterByLaunch('true')

    <button class="btn btn-success"  onClick={() => this._filterByLaunch(true)}>true</button>
  <button class="btn btn-success"  onClick={() => this._filterByLaunch(false)}>false</button>

【讨论】:

猜你喜欢
  • 2013-05-22
  • 1970-01-01
  • 1970-01-01
  • 2017-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多