1. function NumberList(props) {
  2. const numbers = props.numbers;
  3. const listItems = numbers.map((number) =>
  4. <li key={number.toString()}>
  5. {number}
  6. </li>
  7. );
  8. return (
  9. <ul>{listItems}</ul>
  10. );
  11. }
  12.  
  13. const numbers = [, , , , ];
  14. ReactDOM.render(
  15. <NumberList numbers={numbers} />,
  16. document.getElementById('root')
  17. );
  1. //key值最好选用id,没有稳定的id的时候选择index
  2. const todoItems = todos.map((todo) =>
  3. <li key={todo.id/index}>
  4. {todo.text}
  5. </li>
  6. );
  1. function Blog(props) {
  2. const sidebar = (
  3. <ul>
  4. {props.posts.map((post) =>
  5. <li key={post.id}>
  6. {post.title}
  7. </li>
  8. )}
  9. </ul>
  10. );
  11. const content = props.posts.map((post) =>
  12. <div key={post.id}>
  13. <h3>{post.title}</h3>
  14. <p>{post.content}</p>
  15. </div>
  16. );
  17. return (
  18. <div>
  19. {sidebar}
  20. <hr />
  21. {content}
  22. </div>
  23. );
  24. }
  25.  
  26. const posts = [
  27. {id: , title: 'Hello World', content: 'Welcome to learning React!'},
  28. {id: , title: 'Installation', content: 'You can install React from npm.'}
  29. ];
  30. ReactDOM.render(
  31. <Blog posts={posts} />,
  32. document.getElementById('root')
  33. );

react 中文文档案例五 (循环列表)的更多相关文章

  1. react 中文文档案例三 (开关按钮)

    开关按钮制作   import React from 'react'; import ReactDOM from 'react-dom'; class Toggle extends React.Com ...

  2. react 中文文档案例七 (温度计)

    const scaleNames = { c: 'Celsius', f: 'Fahrenheit' }; function toCelsius(fahrenheit) { ) * / ; } fun ...

  3. react 中文文档案例六 (表单)

    class Reservation extends React.Component { constructor(props) { super(props); this.state = { isGoin ...

  4. react 中文文档案例四 (登陆登出按钮)

    import React from 'react'; import ReactDOM from 'react-dom'; class LoginControl extends React.Compon ...

  5. react 中文文档案例二 (头像时间)

    import React from 'react'; import ReactDOM from 'react-dom'; function formatDate(date) { return date ...

  6. react 中文文档案例一 (倒计时)

    1.函数试组件 import React from 'react'; import ReactDOM from 'react-dom'; function Clock(props){ return( ...

  7. phpspreadsheet 中文文档(五)节约内存+PHPExcel迁移

    2019年10月11日14:03:31 节省内存 PhpSpreadsheet在工作表中平均每个单元格使用约1k,因此大型工作簿可以迅速用尽可用内存.单元缓存提供了一种机制,使PhpSpreadshe ...

  8. ASP.NET Core 中文文档 第五章 测试(5.2)集成测试

    原文: Integration Testing 作者: Steve Smith 翻译: 王健 校对: 孟帅洋(书缘) 集成测试确保应用程序的组件组装在一起时正常工作. ASP.NET Core支持使用 ...

  9. talib 中文文档(五):文档导航

    Documentation 安装和问题 快速使用 高级应用 方法分类 Overlap Studies 重叠的研究 Momentum Indicators 动量指标 Volume Indicators ...

随机推荐

  1. 部署和调优 2.9 mysql主从配置-3

    测试 先给主mysql解锁 > unlock tables; 删除一个表 > use db1; > show tables; > drop table help_categor ...

  2. AudioFormat

    AudioFormat   用于访问 一系列语音格式和通道配置常量 例如用于AudioTrack 和AudioRecord中 The AudioFormat class is used to acce ...

  3. springmvc 路径问题

    web项目中的相对路径可以分为二类: 1.以斜杠开头:以斜杠开头的又分为二类(分类依据是斜杠出现的位置):如果出现在java代码或者配置文件(xml,properties等),这个路径叫做后台路径. ...

  4. sharepoint文档库中日期显示详细日期,不显示几天前

    文档库---库设置----栏

  5. java中用正则表达式判断中文字符串中是否含有英文或者数字

    public static boolean includingNUM(String str)throws  Exception{ Pattern p  = Pattern.compile(" ...

  6. SWT简介

    --------------siwuxie095                         SWT 简介:     SWT(Standard Widget Toolkit) 也是基于一个对等体实 ...

  7. ROS Learning-004 beginner_Tutorials 介绍简单的ROS命令

    ROS Indigo beginner_Tutorials-03 介绍简单的ROS命令 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 14.04 ...

  8. Paxos在大型系统中的应用场景

    https://timyang.net/distributed/paxos-scenarios/ 在分布式算法领域,有位非常重要的短发叫Paxos,它的重要性有多高呢?Google的Chubby[1] ...

  9. android自定义视图属性(atts.xml,TypedArray)学习

    是一个用于存放恢复obtainStyledAttributes(AttributeSet, int[], int, int)或 obtainAttributes(AttributeSet, int[] ...

  10. TinkerPop中的遍历:图的遍历中谓词、栅栏、范围和Lambda的说明

    关于谓词的注意事项 P是Function<Object,Boolean>形式的谓词.也就是说,给定一些对象,返回true或false.所提供的谓词在下表中概述,并用于各种步骤,例如has( ...