简体   繁体   English

为什么我收到“Select.js:1555 Uncaught TypeError:无法读取未定义的属性‘isSelectOptGroup’”

[英]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.

相关问题 为什么我收到此错误:“未捕获的TypeError:无法读取未定义的属性'标题'”? - Why am i getting this error: “Uncaught TypeError: Cannot read property 'Title' of undefined”? 为什么我会收到“未捕获的类型错误:无法读取未定义的属性 &#39;body&#39;”? - Why am I getting "Uncaught TypeError: Cannot read property 'body' of undefined"? 为什么我收到此错误:未捕获的TypeError:无法读取undefined的属性&#39;john&#39; - Why am I getting this error: Uncaught TypeError: cannot read property 'john' of undefined 为什么我会收到Uncaught TypeError:无法在分配时读取未定义的属性“ 0”? - why am I getting Uncaught TypeError: Cannot read property '0' of undefined on assign? 我为什么会收到错误:Uncaught TypeError:无法读取未定义的属性“ left” - Why am I getting the error: Uncaught TypeError: Cannot read property 'left' of undefined 为什么会出现Uncaught TypeError:无法读取未定义的属性&#39;displayQuestion&#39;? - Why am i getting Uncaught TypeError: Cannot read property 'displayQuestion' of undefined? 在 Firebase 中,我收到 Uncaught TypeError: Cannot read property &#39;initializeApp&#39; of undefined,但不确定为什么未定义“firebase”? - In Firebase I am getting an Uncaught TypeError: Cannot read property 'initializeApp' of undefined, but not sure why 'firebase' is not defined? 为什么我得到 Uncaught (in promise) TypeError: Cannot read property &#39;type&#39; of undefined? - Why am I getting Uncaught (in promise) TypeError: Cannot read property 'type' of undefined? 为什么我收到“ TypeError:无法读取未定义的属性” length” - Why am I getting 'TypeError: Cannot read property 'length' of undefined' 我为什么会收到TypeError:无法读取未定义的属性“现在” - Why am I getting TypeError: Cannot read property 'now' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM