populate select option in reactjs

时光怂恿深爱的人放手 提交于 2021-01-29 11:22:50

问题


I am trying to populate a dropdown select option in ReactJS from an API but after several attempts instead of getting the values that I want, I got only a single string with all the values concatenated. I tried to format the JSON file in different ways but without any results.

https://codesandbox.io/s/populate-select-option-fu5gd?fontsize=14


回答1:


I have changed your iterator for this:

    <select>
      {this.state.colours[1]?
        this.state.colours[1].color.map(item => {
        return <option>{item}</option>;
      })
    : <option>{''}</option>
    }
    </select>

Here is the complete codesandbox code.



来源:https://stackoverflow.com/questions/57043036/populate-select-option-in-reactjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!