简体   繁体   English

在JSX中反应迭代道具

[英]React iterate props in JSX

I was new in React , and I am confusing about iterating props data in JSX . 我是React新手,对于在JSX迭代props数据感到困惑。

Assume the this.props.data is 假设this.props.data

[
  [
    "2017-1",
    {
      title: "title1"
      describe: "des1"
    }
  ],
  [
    "2017-2",
    {
      title: "title2"
      describe: "des2" 
    }
  ],...
]

How do I iterate data in table? 如何迭代表中的数据?

I was hoping it will render some kind of like this 我希望它会呈现出这样的效果

<tbody>
  <tr>
    <td>2017-1</td>
    <td>title1</td>
    <td>des1</td>
  </tr>
  <tr>
    <td>2017-2</td>
    <td>title2</td>
    <td>des2</td>
  </tr>
  ...
</tbody>

I would map it. 我会映射它。 I'm assuming that the format will always be the same (out of laziness). 我假设格式将始终相同(出于惰性)。

(Please do not run the snippet, it is only for formatting) (请不要运行该代码段,仅用于格式化)

Fiddle: https://jsfiddle.net/gL8drpyd/1/ 小提琴: https : //jsfiddle.net/gL8drpyd/1/

 var data = [ [ "2017-1", { title: "title1" describe: "des1" } ], [ "2017-2", { title: "title2" describe: "des2" } ] ]; let rows = data.map( (item) => ( <tr> <td>{item[0]}</td> <td>{item[1].title}</td> <td>{item[1].describe}</td> </tr> ) ); // put this in the <tbody> in render <tbody> {rows} </tbody> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM