如何在数据中使用 Objects 的嵌套循环呈现 SectionList

How to render SectionList with Nested looped of Objects in data

我有下面的json结构

{
  "title": "Name(s)",
  "type": "Text",
  "data": [
    {
      "source": "DB",
      "title": "All",
      "list": [
        {
          "name": "ABCD",
          "count": 1
        },
        {
          "name": "BCDE",
          "count": 1
        },
        {
          "name": "CDEF",
          "count": 1
        },
        {
          "name": "DEFG",
          "count": 2
        },
        {
          "name": "EFGH",
          "count": 1
        }
      ]
    }
  ]
},
{
  "title": "Category(s)",
  "type": "Text",
  "data": [
    {
      "source": "DB",
      "title": "All",
      "list": [
        {
          "name": "Vegetables",
          "count": 1942
        },
        {
          "name": "Saloon",
          "count": 355
        },
        {
          "name": "General Store",
          "count": 331
        },
        {
          "name": "Restaurants",
          "count": 130
        },
        {
          "name": "Fast Food",
          "count": 108
        }
      ]
    }
  ]
}

我正在尝试将数据显示为喜欢

第一个节标题:"Name(s)"
第一行:"ABCD"
第二行 "BCDE"
第三行 "CDEF"
.
.
.

第二节标题:"Category(s)" 第一行:"Vegetables"
第二行 "Saloon"
第三行 "General Store"
.
.
.
在这里,我是否应该使用 SectionList/Flatlist/ 将它们混合以获得上述结果。

在 flatlist/sectionlist 中,我在 renderSectionHeader 中得到 header Names(s)& Category(s) 部分,但在 renderItem 中, 如何循环 objects 的 "list" 数组。 请告诉我

您必须像下面这样更新数据,

例如:

[
  {
    "title": "Name(s)",
    "type": "Text",
    "data": [
      {
        "name": "ABCD",
        "count": 1
      },
      {
        "name": "BCDE",
        "count": 1
      },
      ...
    ]
  },
  {
    "title": "Category(s)",
    "type": "Text",
    "data": [
      {
        "name": "Vegetables",
        "count": 1942
      },
      {
        "name": "Saloon",
        "count": 355
      },
      ...
    ]
  }
...
]

并使用SectionList显示,

例如:

 ...
    <SectionList
      renderItem={({item, index, section}) => <Text key={index}>{item.name}</Text>}
      renderSectionHeader={({section: {title}}) => (
        <Text style={{fontWeight: 'bold'}}>{title}</Text>
      )}
      sections={this.state.data}
      keyExtractor={(item, index) => item + index}
    />
    ...