[英]How to make correctly autocomplete in React
I want to make autocomplete input of cities in React.我想在 React 中自动完成城市输入。 I have
json
file of cities ~15mb.我有
json
城市文件 ~15mb。 How should I correctly implement it?我应该如何正确实施它? Should I keep this
json
on client side?我应该把这个
json
放在客户端吗?
you could make a request to the server on every keystroke but start the search after say 3 characters您可以在每次击键时向服务器发出请求,但在说 3 个字符后开始搜索
eg searching for London例如搜索伦敦
You would only make the first request after the user has typed in Lon
您只会在用户输入
Lon
后发出第一个请求
15mb seems a lot though, maybe you want to think of filtering this down beforehand so you request less countries back.不过 15mb 似乎很多,也许您想考虑事先过滤掉它,以便您请求更少的国家/地区。 eg make the user select a country beforehand so you only request cities in that country.
例如,预先将用户 select 设为国家/地区,因此您只需请求该国家/地区的城市。 so if they pick USA, then type in
Chi
it would only return cities in the USA
starting with Chi
因此,如果他们选择 USA,则输入
Chi
它只会返回以Chi
开头的USA
城市
I don't think it's a good idea to pull the 15mb client side as that is a huge amount of data我不认为拉 15mb 客户端是一个好主意,因为那是大量的数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.