this sounds like a dumb question but.. I'm starting in JS/MySQL and I'm using a front-end reactJS and back-end nodeJS. I'm trying to make a select form using the values from a table in MySQL database. This should be possible right?
here's my code (using a react component, semantic-ui forms)
class FormulaireCreerCollection extends Component {
constructor() {
super();
this.state = {
categories: []
}
}
async componentDidMount() {
const response = await fetch('http://localhost:3004/getCategories');
const newList = await response.json();
this.setState(previousState => ({
...previousState,
categories: newList,
}));
}
createOptions() {
return this.state.categories.map((categorie, index) => <option key={index} value={index}>{categorie}</option>);
}
state = {}
handleChange = (e, { value }) => this.setState({ value })
render() {
const { value } = this.state
return (
<Form>
<Form.Group widths='equal'>
<Form.Field id='categories' fluid label='Catégories' control='select'>
{this.createOptions()}
</Form.Field>
<Form.Input id='objet'fluid label="Nom de l'objet" placeholder="Nom de l'objet" />
<Form.Input id='image' fluid label="Image de l'objet" placeholder="Image de l'objet" />
</Form.Group>
<Form.TextArea id='descObj' label="Description de l'objet" placeholder="Dites-en nous plus sur l'objet.." />
<Form.Button onClick={this.handleClick}>Ajouter l'objet à la collection</Form.Button>
</Form>
)
}
}
export default FormulaireCreerCollection;
What I would like to do is for example option {first value from table} then option {second value from table} etc..
This sounds really dumb but I haven't found my answer yet. Can anyone help me ?
Here's my json ouput:
[{"nom_categorie":"Alimentation"},{"nom_categorie":"Autres"},{"nom_categorie":"Cartes"},{"nom_categorie":"CD / DVD"},{"nom_categorie":"Consoles"},{"nom_categorie":"Images"},{"nom_categorie":"Informatique"},{"nom_categorie":"Jeux Vidéos"},{"nom_categorie":"Livres"},{"nom_categorie":"Moyens de locomotion"},{"nom_categorie":"Outillage"},{"nom_categorie":"Son"},{"nom_categorie":"Vêtements"}]