【问题标题】:creatable props not working in react-virtualized-select component可创建的道具在 react-virtualized-select 组件中不起作用
【发布时间】:2018-06-01 13:43:54
【问题描述】:

我正在使用 react-virtualized-select 的“可创建”道具。当我编写自定义选项(例如测试代码 4)时,它会显示文本“创建选项“测试代码 4”。但是,当我单击该选项时,下拉列表变为空白,并且该选项也未添加到选项列表中。

演示库链接:https://bvaughn.github.io/react-virtualized-select/

演示库链接源代码https://github.com/bvaughn/react-virtualized-select/blob/master/source/VirtualizedSelect/VirtualizedSelect.example.js

选项:以下列表来自数据库。 dataSource = [ {name: "Test1", label: "Test code 1", type: "text"}, {name: "Test2", label: "Test code 2", type: "text"}, {name: "Test3", label: "Test code 3", type: "text"} ]

组件:

import { Creatable } from 'react-select'

handleOptionChange( selectedValue ) {
   this.setState({
     selectedValue: selectedValue
   });
}

<VirtualizedSelect
   labelKey='label'
   clearable={ clearable }
   disabled={ disabled }
   multi={multi}
   handleOptionChange={this.handleOptionChange}
   options={ dataSource }
   searchable={ searchable }
   selectedValue={ selectedValue }          
   selectComponent={Creatable}
   valueKey='name'
/>

我无法弄清楚我在这里还缺少什么?

提前致谢。

【问题讨论】:

  • 请提供您自己的代码。两个链接都指向react-virtualized-select 项目,其演示页面似乎适用于Creatable 选项。

标签: reactjs dropdown react-virtualized react-select


【解决方案1】:

我有同样的问题。就我而言,问题是由 react-select 的版本引起的。我将 react-select 从 0.9.2 升级到 v1.2.1,这成功了:

"react-select": "v1.2.1"

我还添加了一些示例中存在的以下导入(我不知道这是否至关重要):

import React, { Component, PropTypes  } from 'react';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-04
    • 1970-01-01
    • 2018-04-18
    • 2018-04-16
    • 1970-01-01
    • 2021-12-26
    • 2023-01-22
    • 1970-01-01
    相关资源
    最近更新 更多