React list this.props.children代码实例
程序员文章站
2022-07-02 16:22:00
ul li
Document
ul li
<html> <head> <title>Document</title> <script src="../react.js"></script> <script src="../react-dom.js"></script> <!-- //引用资源,JSX转HTML --> <script src="https://cdn.bootcss.com/babel-core/5.8.38/browser.min.js"></script> </head> <body> <p id="reactContainer"></p> <script type="text/babel"> //babel JSX => HTML const NotesList = React.createClass({ render: function(){ return ( <ol> { React.Children.map(this.props.children, function(child) { return <li>{child}</li> }) } </ol> ) } }) ReactDOM.render( <NotesList> <span>a</span> <span>b</span> </NotesList>, document.getElementById('reactContainer')) </script> </body> </html>
上一篇: Python爬虫获取整个站点中的所有外部链接代码示例
下一篇: [C语言] 数据结构-预备知识结构体