将 JSX 标签包裹在 renderItem 周围?对于<平面列表>或<节列表>在 React-Native 中

发布于 2025-01-10 20:57:01 字数 2119 浏览 5 评论 0原文

有没有办法在 renderItem 周围放置 JSX 标签? (我想使用“react-native-paper”中的 renderItem 的渲染输出放入 Accordion 下拉列表中

<List.Accordion>
  <FlatList
          data={DATA}
          renderItem={renderItem}
          keyExtractor={item => item.id}
  />
</List.Accordion>

)但是,由于我使用的是 ListHeaderComponentListFooterComponent 道具;我只想要 围绕 renderItem;这样 renderItem 的内容位于手风琴内部(作为容器),但不在页眉和页脚周围。

注意:我正在使用SectionList,但我制作了第一个示例 FlatList 来简化

我尝试了以下有效的方法;除了它不在 内渲染:

const AudioTracksScreenData = [
  {
        title: "Reviews",
        renderItem: renderReviews,
        data: audiobookReviewData.result,
        keyExtractor: reviewsKeyExtractor,
  },
]

<SectionList
  sections={AudioTracksScreenData}
  keyExtractor={({ section: { keyExtractor } }) => {
    keyExtractor;
  }}
  renderItem={({ section: { renderItem } }) => (
    <List.Accordion>{renderItem}</List.Accordion>
  )}
  ListHeaderComponent={getHeader()}
/>

我可以使用 让它工作并且.map() ;不过,我希望有一种方法可以使用 来做到这一点。

我拥有...

我想要...(如果您按/单击评论,则会出现可折叠列表;忽略样式差异)

Is there a way to put JSX tags around renderItem? (I want to put the rendered output from renderItem inside an Accordion drop-down using <List.Accordion> from "react-native-paper")

<List.Accordion>
  <FlatList
          data={DATA}
          renderItem={renderItem}
          keyExtractor={item => item.id}
  />
</List.Accordion>

This works; however as I am using a ListHeaderComponent and ListFooterComponent props; I only want the <List.Accordion> around the renderItem; so that the content of renderItem are inside an accordion (as a container) but not around the header and footer.

Note: I am using SectionList, but I made the first example FlatList to simplify

I tried the following which works; except for it not rendering inside a <List.Accordion></List.Accordion>:

const AudioTracksScreenData = [
  {
        title: "Reviews",
        renderItem: renderReviews,
        data: audiobookReviewData.result,
        keyExtractor: reviewsKeyExtractor,
  },
]

<SectionList
  sections={AudioTracksScreenData}
  keyExtractor={({ section: { keyExtractor } }) => {
    keyExtractor;
  }}
  renderItem={({ section: { renderItem } }) => (
    <List.Accordion>{renderItem}</List.Accordion>
  )}
  ListHeaderComponent={getHeader()}
/>

I could get this to work using <ScrollView> and .map() ; However I am hoping there is a way to do this with <SectionList>.

What I have...

What I want... (a collapsible list if you press/click on reviews; ignore styling differences)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文