admin管理员组文章数量:1289586
I'm developing a simple app in React Native that consists of a React Navigation page, a FlatList (on that page), and I would like a simple iOS-friendly search bar to search the contents of that list (only the titles of each item). What is the quickest/easiest/most effective way to achieve this?
Thanks, Eric
I'm developing a simple app in React Native that consists of a React Navigation page, a FlatList (on that page), and I would like a simple iOS-friendly search bar to search the contents of that list (only the titles of each item). What is the quickest/easiest/most effective way to achieve this?
Thanks, Eric
Share Improve this question edited Jan 13, 2018 at 20:25 Eric Phillips asked Jan 13, 2018 at 20:17 Eric PhillipsEric Phillips 5071 gold badge6 silver badges20 bronze badges1 Answer
Reset to default 12Depends on where you store your data. If you are using normal state, you can do the following;
- Define a search text in state, let's say searchInput
- Define your data in state as array of objects, let's say it has title in field title and array is called listItems
- On your flatlist, as your data give
this.state.listItems.filter(item => item.title.includes(this.state.searchInput))
.
When you update your state for searchInput, your list should update accordingly.
本文标签: javascriptSearching a FlatList in React NativeStack Overflow
版权声明:本文标题:javascript - Searching a FlatList in React Native - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741434825a2378572.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论