gpt4 book ai didi

react-native - SectionList 获取 renderSectionHeader 中的节索引

转载 作者:行者123 更新时间:2023-12-03 14:34:28 25 4
gpt4 key购买 nike

<SectionList
sections={[{ data: [1, 2] }, { data: [3, 4] }]}
renderItem={({ item, index }) => ...}
renderSectionHeader={({ section, index }, i) => {
console.log(index, i); // both undefined
}}
/>

我想在 renderSectionHeader 中获取该部分的索引.
例如。 indexsection.data 时应为 0是 [1, 2]和 1 当 section.data[3, 4] .

除了将索引添加到 sections 之外,我如何才能完成此操作数据?

最佳答案

在 react native 的 SectionList 中没有 renderSectionHeader 的部分索引,但是您可以像这样向您的部分添加索引 Prop

 sections={[{ data: [1, 2], index:0 }, { data: [3, 4], index:1 }]}

然后像这样访问renderSectionHeader中的索引
 renderSectionHeader={({section}) => {
console.log(section.index);
}}

关于react-native - SectionList 获取 renderSectionHeader 中的节索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50306554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com