zoukankan      html  css  js  c++  java
  • react 中文文档案例五 (循环列表)

    function NumberList(props) {
        const numbers = props.numbers;
        const listItems = numbers.map((number) =>
          <li key={number.toString()}>
            {number}
          </li>
        );
        return (
          <ul>{listItems}</ul>
        );
      }
      
      const numbers = [1, 2, 3, 4, 5];
      ReactDOM.render(
        <NumberList numbers={numbers} />,
        document.getElementById('root')
      );
    //key值最好选用id,没有稳定的id的时候选择index
     const todoItems = todos.map((todo) =>
        <li key={todo.id/index}>
            {todo.text}
        </li>
    );
    function Blog(props) {
        const sidebar = (
          <ul>
            {props.posts.map((post) =>
              <li key={post.id}>
                {post.title}
              </li>
            )}
          </ul>
        );
        const content = props.posts.map((post) =>
          <div key={post.id}>
            <h3>{post.title}</h3>
            <p>{post.content}</p>
          </div>
        );
        return (
          <div>
            {sidebar}
            <hr />
            {content}
          </div>
        );
      }
      
      const posts = [
        {id: 1, title: 'Hello World', content: 'Welcome to learning React!'},
        {id: 2, title: 'Installation', content: 'You can install React from npm.'}
      ];
      ReactDOM.render(
        <Blog posts={posts} />,
        document.getElementById('root')
      );
  • 相关阅读:
    每日站立会议08
    MAVEN常用命令
    android开发环境搭建
    阻止默认事件和阻止事件冒泡
    C#ActiveX安装项目
    System&Software
    poj 1386 Play on Words 有向欧拉回路
    poj 1033
    120.Triangle
    pandas中 transform 函数和 apply 函数的区别
  • 原文地址:https://www.cnblogs.com/Lolita-web/p/10348219.html
Copyright © 2011-2022 走看看