[英]Setting multiple selected values using React-select
I am having a dropdown where a user can add multiple dropdowns and select a value in it.我有一个下拉菜单,用户可以在其中添加多个下拉菜单和 select 一个值。 While making a GET request, i wanted to keep the selected value in the dropdown, but not sure how to do it.
在发出 GET 请求时,我想将所选值保留在下拉列表中,但不确定该怎么做。 I am able to make the selected value in a single dropdown, but finding it difficult to keep the selected value in multiple dropdowns.
我能够在单个下拉列表中创建选定值,但发现很难在多个下拉列表中保留选定值。 I will be getting the value in an array like this
我将在这样的数组中获取值
values = ["English","Ukraine","Japnese","Korean"];
Then in Select Dropdown for setting the single value i have written it like this:然后在 Select 下拉列表中设置单个值我这样写:
options = [
{value: "english", label: "English"},
{value: "ukraine", label: "Ukraine"},
{value: "japnese", label: "Japnese"},
{value: "korean", label: "Korean"},
{value: "french", label: "French"}
];
<Select
className="profile-module-select-container"
classNamePrefix="profile-module-select"
options={options}
onChange={selected => {
this.handleDropdownSelect(selected, formKey);
}}
onMenuOpen={(e, i, o) => {
this.setState({
selectMenuOpen: true
});
}}
onMenuClose={() => {
this.setState({
selectMenuOpen: false
});
}}
name={name}
value={options.filter((items) => { return items.value === values })}
/>
values
is an array and you would have to loop it over as well and filter it against Options
. values
是一个数组,您还必须遍历它并根据Options
对其进行过滤。 Considering the current implementation, it would be a nested loop, yes.考虑到当前的实现,这将是一个嵌套循环,是的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.