admin管理员组文章数量:1416631
So I am running into this issue where the ponent loads just fine, a dropdown appears, however it shows no label or value. When I click the option it shows a chosen box, but nothing in the box. Please see code below. I am using latest of React-Select for a multi select input and cannot find any documentation on how the array should be built for a multi select.
import React, { Component } from 'react';
import '../index.css';
import Select from "react-select";
export class Invite extends Component {
constructor(props) {
super(props);
this.state = {
multiValue: [],
filterOptions: []
};
this.handleMultiChange = this.handleMultiChange.bind(this);
}
ponentDidMount = () => {
let userList = [];
let list = [];
list = this.props.hub.users;
for (var i = 0; i < list.length; i++) {
userList.push([{label: list[i].userName, value: list[i].userName }]);
}
this.setState({ filterOptions: userList });
}
handleMultiChange(option) {
this.setState(state => {
return {
multiValue: option
};
});
}
render() {
return (<div className="invite">
<Select
name="Users"
placeholder="Users"
value={this.state.multiValue}
options={this.state.filterOptions}
onChange={this.handleMultiChange.bind(this)}
isMulti
/>
</div>);
}
}
So I am running into this issue where the ponent loads just fine, a dropdown appears, however it shows no label or value. When I click the option it shows a chosen box, but nothing in the box. Please see code below. I am using latest of React-Select for a multi select input and cannot find any documentation on how the array should be built for a multi select.
import React, { Component } from 'react';
import '../index.css';
import Select from "react-select";
export class Invite extends Component {
constructor(props) {
super(props);
this.state = {
multiValue: [],
filterOptions: []
};
this.handleMultiChange = this.handleMultiChange.bind(this);
}
ponentDidMount = () => {
let userList = [];
let list = [];
list = this.props.hub.users;
for (var i = 0; i < list.length; i++) {
userList.push([{label: list[i].userName, value: list[i].userName }]);
}
this.setState({ filterOptions: userList });
}
handleMultiChange(option) {
this.setState(state => {
return {
multiValue: option
};
});
}
render() {
return (<div className="invite">
<Select
name="Users"
placeholder="Users"
value={this.state.multiValue}
options={this.state.filterOptions}
onChange={this.handleMultiChange.bind(this)}
isMulti
/>
</div>);
}
}
Share
Improve this question
asked Nov 13, 2018 at 21:30
MappleMapple
151 silver badge6 bronze badges
1 Answer
Reset to default 3you did mistake in ponentDidMount
userList
should be an array of objects instead of array of arrays.
ponentDidMount = () => {
let userList = [];
let list = [];
list = this.props.hub.users;
for (var i = 0; i < list.length; i++) {
userList.push({
label: list[i].userName,
value: list[i].userName
});
}
this.setState({
filterOptions: userList
});
}
for more details visit documentation.
本文标签: javascriptReactSelect dropdown is not displaying options of array or value in inputStack Overflow
版权声明:本文标题:javascript - React-Select dropdown is not displaying options of array or value in input - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745256871a2650155.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论