简体   繁体   English

显示来自 JSON 响应的嵌套对象

[英]Displaying nested objects from JSON response

This may be a simple fix but I'm new to react so I appologize in advance.这可能是一个简单的修复,但我是新手,所以我提前道歉。 I have nested data that I would like to display on a list.我有想要显示在列表中的嵌套数据。 The data is being pulled and displayed below.正在拉取数据并显示在下方。

data: [
{
  "id": 1,
  "domain_url": "localhost",
  "created_on": "2020-05-26",
  "config": [
    {
      "test_name": "test",
      "test_description": "test",
    }
  ]
}
]

I can get the domain_url and created_on displaying just fine but nothing I've tried gets any of the config items to appear.我可以让domain_urlcreated_on显示得很好,但我没有尝试让任何配置项出现。

below is the current method I'm using.以下是我目前使用的方法。

<tbody>
  {this.props.data.map((data) => (
  <tr key={data.id}>
    <td>{data.domain_url}</td>
    <td>
      {data.config.map((sub) => {
        sub.test_name;
      })}
    </td>
    <td>{data.created_on}</td>
    <td>
    ...

how can I get the test name from the config array to display?如何从配置数组中获取要显示的测试名称? Any help would be appreciated.任何帮助,将不胜感激。 Thank you!谢谢!

Your code looks right - I think you just need to add a 'return' in front of your 'sub.test_name;'您的代码看起来正确 - 我认为您只需要在“sub.test_name;”前面添加一个“return”

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

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