问题
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