Mar*_*ill 1 javascript reactjs react-native react-native-flatlist
我有一些这样的数据:
data = [
{name: 'Christmans', date: '.....'},
{name: 'Easter', date: '.....'},
{name: 'Kwanza', date: '.....'}
...
我想用这样的粘性标题显示数据:
-----[即将推出]------------- 此处置顶部分
[今天]
[本星期]
[上星期]
这是在react-native中使用FlatList。如何获得按该顺序格式化的数据?我是否需要创建 4 个不同的平面列表,并在第一个列表中传递即将到来的数据,在第二个列表中传递今天的数据,等等?很高兴看到一个例子。谢谢你!
使用部分列表而不是平面列表
<SectionList
renderItem={({ item, index, section }) => (
<Text key={index}>.{item}</Text>
)}
renderSectionHeader={({ section: { title } }) => (
<Text style={{ fontWeight: "bold" }}>{title}</Text>
)}
sections={[
{ title: "Title1", data: ["item1", "item2"] },
{ title: "Title2", data: ["item3", "item4"] },
{ title: "Title3", data: ["item5", "item6"] },
]}
keyExtractor={(item, index) => item + index}
/>
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请查看此链接 - https://facebook.github.io/react-native/docs/sectionlist
| 归档时间: |
|
| 查看次数: |
3801 次 |
| 最近记录: |