简体   繁体   English

使用 react-select 的多类别下拉菜单

[英]Multi-Category Dropdown using react-select

I want to use react-select for a multi-category dropdown list.我想将 react-select 用于多类别下拉列表。 My use-case is to be able to select one option at max from each category.我的用例是能够从每个类别中最多选择 select 一个选项。 I have explained the given an example below where I want one item at max selected from each category.我已经解释了下面给定的示例,我希望从每个类别中最多选择一个项目。 So we may have a selection like C1I1, C2I3, and C3I1.所以我们可能有一个选择,如 C1I1、C2I3 和 C3I1。 The project I have is using react-select v2.4.4 with react v15.6.2 and material-ui.我的项目是使用 react-select v2.4.4 和 react v15.6.2 和 material-ui。 Can anyone let me know how can I implement this functionality.谁能让我知道如何实现此功能。 Also, if this is already implemented or answered, please direct me towards it.另外,如果这已经实施或回答,请指导我。

  1. Category 1第一类
  • C1I1 C1I1
  • C1I2 C1I2
  • C1I3 C1I3
  1. Category 2第 2 类
  • C2I1 C2I1
  • C2I2 C2I2
  • C2I3 C2I3
  • C2I4 C2I4
  1. Category 3第 3 类
  • C3I1 C3I1
  • C3I2 C3I2

Created a reference pen.创建了一个参考笔。 https://codepen.io/chris495b/pen/QWKmXKE https://codepen.io/chris495b/pen/QWKmXKE

While implementing the select component please dont forget to add isMulti attribute and also include data in the formate shared in the link for grouping.在实现 select 组件时,请不要忘记添加 isMulti 属性,并在链接中共享的格式中包含数据以进行分组。

<Select
        onChange={this.handleChange}
        isMulti
        defaultValue={colourOptions[1]}
        options={groupedOptions}
        formatGroupLabel={formatGroupLabel}
      />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM