简体   繁体   English

如何使用 javascript(Reactjs) 作为前端和 node.js 作为后端创建依赖下拉列表

[英]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.

相关问题 如何在 javascript 前端使用 async await 从 async await node.js 后端接收数据 - how to use async await on javascript frontend to receive data from async await node.js backend 如何在没有前端的情况下使用 Postman 在 Node.js Express 后端服务器上测试 Passport JS Google OAuth - How to test Passport JS Google OAuth on Node.js Express backend server without a frontend using Postman 如何将数据从前端jQuery传递到后端node.js - How to pass data from frontend jQuery to backend node.js 如何在 node.js 后端使用 usestate 并响应前端 - how to use usestate with node.js backend and react frontend 如何使用来自后端的数据和 node.js 在前端绘制图表? - How to plot a chart in the frontend using data from the backend with node.js? 如果我在前端使用 vanilla js 而在后端使用 node.js,如何在同一端口上运行前端和后端? - How to run frontend and backend on same port , if I am using vanilla js on frontend and node js on backend? 分离的前端与bone.js和node.js后端令牌 - Separated frontend with backbone.js and node.js backend token Node.js 后端和前端共享代码 - Node.js sharing code between backend and frontend Azure:连接/代理前端(React)到后端(Express/node.js) - Azure: Connect/Proxy Frontend (React) to Backend (Express/node.js) Node.js充当前端应用程序的后端服务器 - Node.js serve as a backend server for frontend app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM