现在需要在页面上显示一本书的章节,章节内容存放到一个数组里面:

const lessons = [
{ title: 'Lesson 1: title', description: 'Lesson 1: description' },
{ title: 'Lesson 2: title', description: 'Lesson 2: description' },
{ title: 'Lesson 3: title', description: 'Lesson 3: description' },
{ title: 'Lesson 4: title', description: 'Lesson 4: description' } ]

现在需要你构建两个组件。一个组件为 Lesson 组件,渲染特定章节的内容。可以接受一个名为 lesson 的 props,并且把章节以下面的格式显示出来:

<h1>Lesson 1: title</h1>
<p>Lesson 1: description</p>

点击每个章节的时候,需要把章节在列表中的下标和它的标题打印(console.log)出来,例如第一个章节打印: 0 - Lesson 1: title,第二个章节打印:1 - Lesson 2: title.另外一个组件为 LessonsList,接受一个名为 lessons 的 props,它会使用 Lesson 组件把章节列表渲染出来。

class Lesson extends Component{
render(){
const {lesson} = this.props
return (
<div onClick={() => console.log(`${this.props.index} - ${lesson.title}`)}>
<h1>{lesson.title}</h1>
<p>{lesson.description}</p>
</div>
)
} } class LessonList extends Component{
render(){
return(
<div>
{this.props.lessons.map((lesson,id)=>{
return <Lesson lesson={lesson} id={id}/>
})}
<div/>
) }
}

最新文章

  1. C++中inline这个玩意儿
  2. .NET开发Windows Service程序 - Topshelf
  3. 银联接口(注意项&amp;备忘)
  4. IntentFilter
  5. Python实现简易端口扫描器
  6. Deadclock on calling async methond
  7. awkOFS问题
  8. 【Python】 hash值计算 hashlib &amp; hmac
  9. pyspider安装提示:got an unexpected keyword argument &#39;io_loop&#39;的解决办法
  10. map,set和weakmap,weakset
  11. 2018-05-27-computer-using-hints-电脑使用帮助[持续更新]
  12. DevExpress WinForms v18.2新版亮点(三)
  13. 【Unity Shader】一、顶点函数(vertex)和片元函数(fragment)
  14. iconfont 入门级使用方法
  15. R7—左右内全连接详解
  16. angularJS简介及其特点—— 五大特性,加快 Web 应用开发
  17. bzoj3802: Vocabulary
  18. Python 读写xlsx
  19. linux USB HOST之EHCI和OHCI【转】
  20. python自动化测试windows gui

热门文章

  1. sql server 查看表中某一字段的排序规则
  2. MongoDB divide 使用之mongotempalte divide
  3. NSInvocation简单总结
  4. KEIL仿真出现 EVALUATION MODE
  5. 14.JdbcUtils框架
  6. mORMot学习笔记 (一)
  7. Linux查找并杀死僵尸进程(转)
  8. Kinect 深度测量原理
  9. 面试题——常见的gc算法有哪些?
  10. 海康威视面试-java应用开发