[英]How to remove null selected values from a react-select multi select
I have been trying to set up react-select
but when I enable isMulti
there is always two selected blank values in the selection box.我一直在尝试设置react-select
但是当我启用isMulti
时,选择框中总是有两个选定的空白值。
I have tried setting default values, using state to control the Select
but it keeps showing these two blank values when I load the page.我已经尝试设置默认值,使用 state 来控制Select
但是当我加载页面时它一直显示这两个空白值。 Here are some code snippets of the things I have tried:以下是我尝试过的一些代码片段:
<Select
isMulti
/>
<Select
isMulti
defaultValue={[]}
/>
<Select
isMulti
options={majors().map((element: any) => {
return { value: element[2], label: element[2] }
})}
/>
<Select
isMulti
defaultValue={[]}
options={majors().map((element: any) => {
return { value: element[2], label: element[2] }
})}
/>
interface Option {
value: String,
label: String
}
let def : Option[] = []
<Select
isMulti
defaultValue={def}
options={majors().map((element: any) => {
return { value: element[2], label: element[2] }
})}
/>
Not entirely sure the reason for this, but what ended up fixing the problem was wrapping the <Select>
inside of a <div>
.不完全确定这样做的原因,但最终解决问题的方法是将<Select>
包装在<div>
中。
This did the trick:这成功了:
<div>
<Select
isMulti
defaultValue={[]}
options={majors().map((element: any) => {
return { value: element[2], label: element[2] }
})}
/>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.