[英]Why I am getting "Select.js:1555 Uncaught TypeError: Cannot read property 'isSelectOptGroup' of undefined"
I am new to react and I am trying to show dynamic values in the dropdown by fetching from the dummy api .我是新手,我试图通过从虚拟 api 获取来在下拉列表中显示动态值。 But I am getting error with select.js and my web page is displayed blank.
但是我在使用 select.js 时遇到错误并且我的网页显示为空白。
class Test extends React.Component
{
constructor(props) {
super(props);
this.state = {
dropdown:[]
};
this.getJSONdata=this.getJSONdata.bind(this);
}
componentWillMount() {
this.getJSONdata();
}
getJSONdata()
{
var temp=[];
fetch('http://dummy.restapiexample.com/api/v1/employees')
.then((response) => {
return response.json();
})
.then((myJSON)=>
{
console.log(JSON.stringify(myJSON));
for(let i = 0; i<15;i++)
{
var data = myJSON[i];
var joined = {value:data.employee_name};
temp.push(joined);
}
console.log("obtained jSON data" + JSON.stringify(temp));
this.setState({
dropdown:temp});
});
}
render()
{
return (
<select
id = "test"
options={this.state.dropdown}
</Select>
);
}
export default Test;
On running I am getting error:运行时出现错误:
Uncaught TypeError: Cannot read property 'isSelectOptGroup' of undefined
未捕获的类型错误:无法读取未定义的属性“isSelectOptGroup”
Where I am going wrong?我哪里出错了? Could anyone please help me with this issue.
任何人都可以帮我解决这个问题。
Its late but I hope it helps,If you are using AntD晚了,但我希望它有所帮助,如果您使用的是 AntD
You have written your select component wrong.你写错了你的选择组件。 Ant Design select doesn't have options props.
Ant Design select 没有选项道具。 change your code to this.
将您的代码更改为此。
<Select
value={this.state.yourValue}
onSelect={this.onValueSelected}>
{
this.state.dropdown.map((item: any, index: number) => {
return <Option key={index} value={item.value}>
{item.label}
</Option> })
}
</Select>
And if you write anything else between <Select> </Select>
you will get the same error如果你在
<Select> </Select>
之间写任何其他东西,你会得到同样的错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.