I want to show a dynamic selection with values from 1 to 100 in the react component.
In Angular 2
<select> <option *ngFor="let i of numbers">{{i}}</option> </select> <!--numbers is an array [1,2,3,4,...100]-->
How is it in real life?
You can use map for numbers and dynamically create parameters as follows:
map
<select> { numbers.map(el => <option value={el} key={el}> {el} </option>) } </select>
Check out this example:
var numbers = [...Array(100).keys()]; var App = () => { return( <select> { numbers.map(el => <option value={el} key={el}> {el} </option>) } </select> ) } ReactDOM.render(<App/>, document.getElementById('app'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id='app'/>
RepeatModule is equivalent in Reactjs
RepeatModule
ReactDOM.render(<RepeatModule items={items} />, document.getElementById('react-content'));
Live demo
I would recommend the following solution.
Inside the render and return in Reactjs:
{ myArrayOfData.map((val, index) => { return ( <div key={index}> { val } </div> ); }) }
myArrayOfData can be, for example, this.state.myArray .
this.state.myArray
Source: https://habr.com/ru/post/1267250/More articles:How to associate a property of a nested model with a kendo grid column? - c #Flutter - display new widgets on click - dartJupyter kernel dies on Ubuntu - python-3.xGraphQL Schema with Sangria - jsonFlexbox non-expandable parent container overflow in Chrome - htmlWrite a copyable interface more elegant than Java - genericsWhat is the Change trigger directive in Textarea? - angularAngular 2: formGroup expects an instance of FormGroup. Request to transfer - angularAngular 2/4 Change Form Fill FormArray Controls - angularHow do I access python command line options (not args) - pythonAll Articles