javascript - 如何在 React Native 中的粘性标题 FlatList 中搜索?
问题描述
我实现了一个带有粘性标头的 FlatList,它从Content.json
.
但是当我实现搜索功能时,出现以下错误。
解决方案
了解您想要实现的目标,您应该:
<FlatList
data={filteredContent}
renderItem={this.renderContent}
keyExtractor={(item) => item.name}
stickyHeaderIndices={this.state.stickyHeaderIndices}
/>
然后,在你的renderContent
:
renderContent = ({ item }) => {
const content = item
if (content.header) {
return (
<ListItem itemDivider>
<Body>
<Text style={styles.headerStyle}>{content.name}</Text>
</Body>
</ListItem>
);
} else if (!content.header) {
return (
<ListItem style={{marginLeft: 0}}>
<Body>
<Text>{content.name}</Text>
</Body>
</ListItem>
);
}
};
请记住,该函数renderItem
为您提供了item
一个对象内部,并且它具有该名称,因此您不能仅将其用作content
.
推荐阅读
- java - 如何在 Spring Data MongoDB 的 ProjectionOperation 中投影 map 和 reduce?
- javascript - 在不使用填充的情况下向 Material UI Grid 添加一个空白列
- git - 克隆 git 存储库时出现 SSL 证书错误
- amazon-web-services - 当 SQS 消息发送到死信队列时如何生成警报?
- jenkins-pipeline - Cloudbees Jenkins:在不同的 Jenkins 实例之间触发下游作业
- python - anaconda/spyder scikit 学习更新 0.21.3 到 0.22.2
- swift - 无法在领域中的日期后快速过滤
- asp.net-core - SwaggerUI 未构建 - 浏览器 ASP.NET Core API 中的空白页面
- android - 如何动态设置导航菜单?
- python - 这是功能还是错误?Windows 10 python time.sleep() 挂起时时钟翻转到午夜