如何在数组中表示一本书的内容

How to represent a book content in an array

我有一组信息,我想在一个数组中表示,然后将它们拉出到一个 React Native 平面列表中,但我不知道该怎么做。

基本上,有不同的标题和字幕,每个字幕都有一个内容。我想通过列表映射并显示它们。

下面是我目前的代码,但它似乎不起作用。

const NigLawList= ({navigation}) => {
  const [people, setPeople] = useState([
      {Law: "Evidence Act", id: "1",
      part:[ {name: "Title one", meaning: "Content is here"},
      {name: "Title 2", meaning: " Content is here"}
      
    ]

},
])

试试这个方法

const [data, setData] = useState([{"Law":"Evidence Act","id":"1","part":[{"name":"Title one","meaning":"Content is here"},{"name":"Title 2","meaning":"Content is here"}]}]);

renderSubtitleAndContent = (parts) => {
    return parts.map(part => {
      return (
        <View>
          <Text>{part.name}</Text> <-- Subtitle here -->
          <Text>{part.meaning}</Text> <-- Content here -->
        </View>
      );
    });
 };

<FlatList
        data={data}
        renderItem={({ item }) => (
          <Text>{item.Law}.</Text> <-- title here -->
          {this.renderSubtitleAndContent(item.parts)} <-- render Subtitle And Content -->
        )}
/>