react jsx语法中怎么实现for循环?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="react.js"></script> <script src="react-dom.js"></script> <script src="babel.min.js"></script> <style> .yew{color:red;} .no{color:#000;} </style> </head> <body> <div id="root"></div> <script type="text/babel"> class Hello extends React.Component { render(){ var list = (length) => { var res = []; for(var i = 0; i < length; i++) { res.push(<h2 key={i}>hello react</h2>) } return res } return ( <div>hello {list(this.props.length)} </div> ) } } var helloData = 5 ReactDOM.render( <Hello length = {helloData}/>, document.getElementById('root') ); </script> </body> </html>
更多web前端开发知识,请查阅 HTML中文网 !!
以上就是react jsx语法中怎么实现for循环?的详细内容,更多请关注易知道|edz.cc其它相关文章!