Answer the question
In order to leave comments, you need to log in
How, when choosing an option from a select, render the second unique select associated with it?
For example, I chose the region of Russia in the select, a list of districts of this region appears, then a list of settlements. Are there examples online? )
Answer the question
In order to leave comments, you need to log in
const states = ['', 'Moscowskaya'];
const cities = {
'Moscowskaya': ['Moscow']
};
const Selects = React.createClass({
getInitialState() {
return { state: '' };
},
_onStateChange(event) {
this.setState({ state: event.target.value });
},
render() {
return (
<div>
<select onChange={this._onStateChange}>{states.map((state) => <option key={state} value={state}>{state}</option>)}</select>
{this.state.state ? <select>{cities[this.state.state].map((city) => <option key={city} value={city}>{city}</option>)}</select> : null}
</div>
);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question