I
I
ivan gi2015-08-04 13:34:54
JavaScript
ivan gi, 2015-08-04 13:34:54

How to add elements to select in react.js?

How to add elements to select in react.js?

<select >
  <option value="1">Один</option>
  <option value="2">Два</option>
</select>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
artemdemo, 2015-08-08
@artemdemo

Wrap the select weight in a separate component and re-render it every time there is new data. Something like this:

var Select = React.createClass({
    getInitialState: function() {
        return {
            options: optionsService.getoptions()
        };
    },

    renderOptions: function() {
        return this.state.genres.map(function(genre, i){
            return (
                <option value={i} value={i}>Один</option>
            )
        })
    },

    render: function() {
        return (
            <select>
                { this.renderOptions() }
            </select>
        )
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question