react-semantic-redux-form selectField 多个

react-semantic-redux-form selectField multiple

我正在尝试将 react-semantic-redux-form SelectField 与多个选项一起使用,这样用户就可以 select 多个选项,如果已经设置了一个,那么这应该显示为已选中。 我也在使用 redux-form 和 semantic0ui-react。 我在尝试包含多个 select 离子时遇到错误。

我的包含语句是:

import { SelectField } from "react-semantic-redux-form";

我的状态是:

state = {
    relationships: ["some entry"],

    relationshipOptions: [],

};

元素代码为:

<Grid.Column>
<Field
    component={SelectField}
    name="relationships"
    label="Your Relationships"
    options={relationshipOptions}
    multiple
    placeholder="Select to add a relationship"
/>

我得到如下错误

Dropdown `value` must be an array when `multiple` is set. Received type: `[object String]`. 
in Dropdown

relationshipOptions的方式是错误的,应该是对象数组

const relationshipOptions = [
   { key: "single", value: "single", text: "single" },
   { key: "married", value: "married", text: "married" }
];

这是工作示例,Code Sandbox

另外,如果数组中有 single, married。你可以这样做,

let relationshipOptions = ["single", "married"].map((x) => {
   return ({
     key: x,
     value: x,
     text: x
  });
});