【问题标题】:API display array map in reactAPI 在反应中显示数组映射
【发布时间】:2020-08-20 08:49:02
【问题描述】:

我在地图中显示这 2 个循环时遇到问题。我使用此地图进行显示,但似乎无法同时显示两个循环。

我可以只在一个循环中显示它们吗?像循环内循环?在这里需要帮助 tia

Choices Data

{testQuestionData.map(({choices}) => (
   <div>{choices.map((tchoices)=>
      <div>
         {tchoices.testChoices}
      </div>
        )}
   </div>
))} 

Question Data

{testQuestionData.map(td=>(
  <div className="col-md-12">
     {td.question.testQuestion}
         <label>Choices: {td.choicesDisplay}</label>
   </div>
))}

{
  "question": {
    "testQuestion": "Earth is flat?",
  },
  "choices": [
    {
      "testChoices": "true",
      "
    }
   {
      "testChoices": "false",
      "
    }
  ]
}

【问题讨论】:

  • 嘿,你能说一下你遇到的错误吗?
  • 我没有错误,需要一些帮助我可以用那个 json 做一个循环吗?使用地图

标签: arrays reactjs loops


【解决方案1】:

您的数据格式错误。在测试选择之后您有一个随机的",而在选择之间没有,

您的数据应如下所示

{
    "question": {
      "testQuestion": "Earth is flat?",
    },
    "choices": [
      {
        "testChoices": "true",        
      },
     {
        "testChoices": "false",        
      }
    ]
  }

【讨论】:

    猜你喜欢
    • 2019-06-12
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 2020-01-07
    • 2021-11-09
    • 2020-07-29
    • 1970-01-01
    • 2020-08-10
    相关资源
    最近更新 更多