简体   繁体   English

如何在 React Native 中实现搜索?

[英]How to implement searching in react native?

In my app I have the search bar and screen with some static text on it.在我的应用程序中,我有搜索栏和屏幕,上面有一些 static 文本。 How can I display search results and when you click on one of them open a new page with this result?如何显示搜索结果,当您单击其中一个时,如何打开包含此结果的新页面? (I'm not asking you to write code, I want to understand it from the point of view of logic) (我不是要你写代码,我是想从逻辑的角度去理解)

Well you would basically create a state for your search string and results.好吧,您基本上会为您的搜索字符串和结果创建一个 state。 Then you would fetch results based on your search string and store the results in your result state.然后,您将根据搜索字符串获取结果并将结果存储在结果 state 中。 Then check if your results has some value in it and render it.然后检查你的结果是否有一些价值并渲染它。

To show an individual result on new screen, you create a new screen and navigate to the new screen with the id of the clicked result as your params.要在新屏幕上显示单个结果,请创建一个新屏幕并使用单击结果的 id 作为参数导航到新屏幕。 then you can use the id from the params and fetch the individual result and display it.然后您可以使用参数中的 id 并获取单个结果并显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM