Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何在react select中不允许重复_Reactjs - Fatal编程技术网

Reactjs 如何在react select中不允许重复

Reactjs 如何在react select中不允许重复,reactjs,Reactjs,我是新的反应,并学习如何使用反应选择。此外,我想确保输入字段中只输入唯一的值,但下面的代码不允许我实现这一点,我还使用了indexOf,但没有结果,因此我真的需要您的帮助: const onSelectAll = () => { const filteredOptions = options.filter(option => { return filterOption(option as any,

我是新的反应,并学习如何使用反应选择。此外,我想确保输入字段中只输入唯一的值,但下面的代码不允许我实现这一点,我还使用了indexOf,但没有结果,因此我真的需要您的帮助:

const onSelectAll = () => {
                    const filteredOptions = options.filter(option => {
                        return filterOption(option as any, inputValue)
                    });
                    const uniqueValues = filteredOptions.filter((item,i)=>{
                          filteredOptions.indexOf(item)===i
                    })
                    setValue([...value, ...uniqueValues], setValueAction);
                };

上面的onSelectAll函数是“全选”按钮的单击处理程序,该按钮将用户从菜单中键入的所有对应值添加到react Select input中。

请添加一个片段或指定您的边缘大小写,以澄清bloker和正在发生的事。@mdiorio,简而言之,请告诉我如何实现只选择唯一值并将其放入react select输入?