Прежде всего, вам необходимо преобразовать ваши данные в соответствии с форматом, который поддерживает SectionList в React Native.
let RequiredPictures = {
"Additional product": [
{
"required_picture_id": "001",
"label": "MRI",
"has_picture": true,
"url": "https:bbymakeitright.png"
},
{
"required_picture_id": "002",
"label": "MR",
"has_picture": true,
"url": "https:bbymakeitright.png"
}
],
"Additional product two": [
{
"required_picture_id": "003",
"label": "IMR",
"has_picture": true,
"url": "https:bbymakeitright.png"
},
{
"required_picture_id": "004",
"label": "IR",
"has_picture": false,
"url": ""
}
]
}
let newData = [
{ title: Object.keys(RequiredPictures)[0], data: RequiredPictures[Object.keys(RequiredPictures)[0]] },
{ title: Object.keys(RequiredPictures)[1], data: RequiredPictures[Object.keys(RequiredPictures)[1]] },
]
console.log(newData)
Затем вы можете использовать эти данные для отображения вашего списка разделов
import React, { Component } from 'react';
import { SectionList, Text, SafeAreaView } from 'react-native';
const RequiredPictures = {
"Additional product": [
{
"required_picture_id": "001",
"label": "MRI",
"has_picture": true,
"url": "https:bbymakeitright.png"
},
{
"required_picture_id": "002",
"label": "MR",
"has_picture": true,
"url": "https:bbymakeitright.png"
}
],
"Additional product two": [
{
"required_picture_id": "003",
"label": "IMR",
"has_picture": true,
"url": "https:bbymakeitright.png"
},
{
"required_picture_id": "004",
"label": "IR",
"has_picture": false,
"url": ""
}
]
}
export default class App extends Component {
render() {
let newData = [
{ title: Object.keys(RequiredPictures)[0], data: RequiredPictures[Object.keys(RequiredPictures)[0]] },
{ title: Object.keys(RequiredPictures)[1], data: RequiredPictures[Object.keys(RequiredPictures)[1]] },
]
return (
<SafeAreaView style={{ flex: 1, marginTop: 20 }}>
<SectionList
sections={newData}
keyExtractor={(item, index) => item + index}
renderSectionHeader={({ section }) => (
<Text style={{ fontSize: 20, backgroundColor: 'gray' }}>{section.title}</Text>
)}
renderItem={({ item }) => <Text>{item.label}</Text>}
/>
</SafeAreaView>
);
}
}
Надеюсь, это поможет вам. Не стесняйтесь сомнений.