欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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>