如何在react-select v2中创建optgroup?

oun*_*uni 15 javascript reactjs react-select

我想在我的react-select列表中包含optgroup,但是似乎没有任何地方记录它。我具有以下结构,我从https://github.com/JedWatson/react-select/issues/59中的注释中提取了以下结构:

render() {
  const options = [
    {
      label: "Group 1",
      children: [
        { label: "Group 1, option 1", value: "value_1" },
        { label: "Group 1, option 2", value: "value_2" }
      ]
    },
    { label: "A root option", value: "value_3" },
    { label: "Another root option", value: "value_4" }
  ];
  return <Select options={options} />
}
Run Code Online (Sandbox Code Playgroud)

我希望“组1”是一个optgroup,将选项1和2作为子项。而是,“组1”仅作为常规选项出现。有谁知道“ Group 1”中将其变成optgroup的正确密钥是什么?

我已经尝试过“儿童”和“价值观”,但没有任何效果。

oun*_*uni 27

options是魔术键:

render() {
  const options = [
    {
      label: "Group 1",
      options: [
        { label: "Group 1, option 1", value: "value_1" },
        { label: "Group 1, option 2", value: "value_2" }
      ]
    },
    { label: "A root option", value: "value_3" },
    { label: "Another root option", value: "value_4" }
  ];
  return <Select options={options} />
}
Run Code Online (Sandbox Code Playgroud)

这呈现了我所期望的方式。