I have a JSON of courthouse that contains one id and one name. The JSON contains an unlimited number of courthouses. I need to create a <Select> full of <Option>. the <Option> value will be the id, and the <Option> content will be the name.
So i got this function
createSelectCourtHouse:function(){
return (
<Form.Field className='form-control' type='select' name='request.courthouse_id' id='accused_lastname' placeholder="Nom de l'accusé" id='accused_lastname' onChange={this.handleChange.bind(this, 'accused_lastname')}>
this.state.courthouseData.forEach(function(courthouse) {
return (
<option value={courthouse.i}>{courthouse.name}</option>
);
})
</Form.Field>)
},
but it seems like i can't do a forEach inside a return. So i tried this way :
var field = (
<Form.Field className='form-control' type='select' name='request.courthouse_id' id='accused_lastname' placeholder="Nom de l'accusé" id='accused_lastname' onChange={this.handleChange.bind(this, 'accused_lastname')}>
this.state.courthouseData.forEach(function(courthouse) {
<option value={courthouse.id}>{courthouse.name}</option>
});
</Form.Field>
)
return field;
But it doesnt work. I feel like im close to getting the answer but simply cant get the hand on it. Any ideas ?
TL;DR : I need to create a select with option filled with value from a JSON.
map