[英]How to create dependent dropdown list using javascript(Reactjs) as frontend and node.js as backend
If i select city A then it explore Areas in that city.如果我选择城市A,那么它会探索该城市的区域。 After I selecting the area it also explore streets in that area.
在我选择该区域后,它还会探索该区域的街道。 After that i select street, It will be stored in my Database
之后我选择街道,它将存储在我的数据库中
Your database should be like this:你的数据库应该是这样的:
Cities城市
id - name - other fields id - 姓名 - 其他字段
Areas地区
id - name - cityId - other fields id - name - cityId - 其他字段
Streets街道
id - name - areaId - other fields id - name - areaId - 其他字段
When you want to save the street (let's say you are saving to restaurants table), then your restaurants table should be like:当您想保存街道时(假设您要保存到餐厅表),那么您的餐厅表应如下所示:
Restaurants餐厅
id - name - streetId - other fields id - name - streetId - 其他字段
Only saving the streetId will be enough for you, because from streetId you can get which city or area the street is in. Don't forget to check if streetId exists before saving the restaurant.只保存 streetId 对你来说就足够了,因为从 streetId 你可以得到街道所在的城市或区域。不要忘记在保存餐厅之前检查 streetId 是否存在。 So that you can send a meaningful response to the client.
这样您就可以向客户端发送有意义的响应。
On the first load of your web page, you should only get the city list.在您的网页第一次加载时,您应该只获得城市列表。 Once a city is picked, then you should get the area list.
选择一个城市后,您应该会获得区域列表。 Once an area is picked, you should get the street list.
选择一个区域后,您应该会获得街道列表。 Otherwise, it will be too much data to fetch from the database.
否则,从数据库中获取的数据将太多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.