【问题标题】:Nested flatlist with array for JSON data - React Native带有 JSON 数据数组的嵌套平面列表 - React Native
【发布时间】:2020-10-03 10:23:54
【问题描述】:

尝试将它们显示为列表项,日期(2020-05-10,2020-05-22 等...)作为标题和 Hokey,日期标题下的购物作为列表项。

{
   "2020-05-10":[
      {
         "title":"Hiking"
      },
      {
         "title":"Shopping"
      }
   ],
   "2020-05-22":[
      {
         "title":"Hiking"
      },
      {
         "title":"Football"
      }
   ],
   "2020-05-28":[
      {
         "title":"Hiking"
      },
      {
         "title":"Football"
      },
      {
         "title":"Cricket"
      }
   ]
}

【问题讨论】:

  • 对不起,您的问题完全无法理解。问题出在哪里?你试过什么没用?一个 sn-p 的代码,不仅是数据,也会很有用。也可能与打字稿无关,您的问题似乎与类型无关。

标签: javascript typescript react-native


【解决方案1】:

使用<SectionList/>

https://reactnative.dev/docs/sectionlist

类似于 FlatList 和 ScrollView,但允许部分(标题)和您需要的演示文稿。您必须以不同的方式映射数据,例如:

const sectionListData = [
 {
  sectionHeader: '22-05-2020',
  data: [{title: 'Football}, {title: 'Hockey'}]
 },
 ...
]

【讨论】:

    猜你喜欢
    • 2018-06-09
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 1970-01-01
    • 2023-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多