从api提取的项目未显示在下拉列表中react-select

时间:2019-07-02 05:57:21

标签: reactjs react-select

使用React应用程序并尝试在类似功能的下拉列表中显示选项,我正在使用<Select>的{​​{1}}标签。使用api提取一切正常,并且可以使用数据。但是,它在下拉菜单中没有显示任何选项。

react-select

2 个答案:

答案 0 :(得分:2)

这对我有用。您只需将数组作为prop options传递给Select组件。您还可以将onChange处理函数作为prop以及当前选定的值传递。

render() {
    return (
      <div>
        <Select
        options={this.state.values}>
        </Select>
      </div>
    )
  }

您可以在他们的npm页面上找到更多相关信息 https://www.npmjs.com/package/react-select

答案 1 :(得分:1)

react-select需要comp->DoStuff( dt );属性。

您可以使用playerGunComponent.timer += _time.deltaTime;创建options数组,

option

用法

this.state.values

注意::还要确保从API调用中获得响应,要确保获得响应,必须使用 let option = [] if (this.state.values.length > 0) { this.state.values.forEach(role => { let roleDate = {} roleDate.value = role.RoleId roleDate.label = role.RoleName option.push(roleDate) }) } -<Select options={options} /> 来获取数据。

Demo