【问题标题】:How to represent a book content in an array如何在数组中表示书籍内容
【发布时间】:2020-11-03 08:55:25
【问题描述】:

我有一组信息,我想在一个数组中表示,然后将它们拉到一个 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"}
      
    ]

},
])

【问题讨论】:

  • 请提供有关您尝试执行的代码的更多信息并完成错误
  • 其实我还没有任何代码。我只是想知道我是否可以在 react native flatlist 中显示这种信息
  • 请查看上图

标签: javascript arrays reactjs react-native react-native-flatlist


【解决方案1】:

试试这个方法

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 -->
        )}
/>

【讨论】:

  • 这工作正常,但所有平面列表都没有通过名称映射
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-30
  • 1970-01-01
  • 2021-09-17
  • 1970-01-01
  • 2020-08-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多