列表渲染

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
    <script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>

</head>
<body>
    <div id="app"></div>
    
    <script type="text/babel">
        // 封装App 组件
        class App extends React.Component{ 
            constructor(){
                super(); 
                this.state = { 
                    names:['abc','cdf','dff','efr','wed'],
                    numbers:[110,123,456,10,30,50,345,456]
                }  
            }

            render(){  
 
                return (  
                    <div>   
                       <ul>
                            {
                                this.state.names.map(item=>{
                                    return <li>{item}</li>
                                })
                            }
                        </ul>

                        <h2>数字列表(过滤)</h2>
                        <ul>
                            {
                              this.state.numbers.filter(item => item > 50).map(item=> <li>{item}</li>)
                            }
                        </ul>


                        <h2>数字列表(截取)</h2>
                        <ul>
                            {
                              this.state.numbers.slice(0,4).map(item=> <li>{item}</li>)
                            }
                        </ul>

                    </div> 
                )
            } 
        }
 
        ReactDOM.render(<App/>,document.getElementById('app')); 
    </script>
</body>
</html>
posted @ 2021-08-10 18:00  13522679763-任国强  阅读(20)  评论(0)    收藏  举报