reactjs - How to use an array as option for react select component -


if wanna replace options

<option value="a">apple</option> <option value="b">banana</option> 

in given example use of array in react jsx file,how proceed ?

<select value="b">     <option value="a">apple</option>     <option value="b">banana</option> </select> 

best regards

blue

because it's javascript, there million ways. way take map container generate guts. loop or whatever work fine.

var answer = react.createclass({      render: function() {          var data     = ['this', 'example', 'isnt', 'funny'],             makeitem = function(x) {                 return <option>{x}</option>;             };           return <select>{data.map(makeitem)}</select>;      }  }; 

or in es6 in more modern react can just

var answer = props =>      <select>{props.data.map(x => <option>{x}</option>)}</select>; 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -