在React JSX中的循环内循环 [英] Loop inside of a loop, in React JSX

查看:414
本文介绍了在React JSX中的循环内循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在React,JSX,循环内部的循环中渲染 像下面这样:

I am trying to render in react, jsx, a loop inside of a loop Like bellow:

{this.state.ans.map(function(item) {
    return (
        {this.state.quest.map(
            function(item1) {return (item1)}
        )}        
        {item}
    )
})}

这不起作用任何其他建议

This does not work any other suggestions

推荐答案

您在第一个map语句中忘记了包装div:

You forgot the wrapping div in your first map statement:

render() {
  return (
    <div>
      {this.state.ans.map(item =>
        <div> // this div was missing
          {this.state.quest.map(quest => quest)}
          {item}
        </div>
      )}
    </div>
  )
}

这篇关于在React JSX中的循环内循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆