开发者

Best practices on displaying suburbs on a global site based on the country selected

开发者 https://www.devze.com 2023-03-10 23:50 出处:网络
Let\'s say a user from a global site selects his/her country from a drop down list. I would like to present the user with a 开发者_开发技巧list of suburbs of that country.

Let's say a user from a global site selects his/her country from a drop down list. I would like to present the user with a 开发者_开发技巧list of suburbs of that country.

The problem I find is that it may be a lot of work populating the SQL database with country-suburb relations. And having done that, I would imagine each user would have to load the list of suburbs dynamically from the database which doesn't scale too well.

Another way is to use JavaScript and hard code the suburbs so they come up when the country is selected. Again this way seems like a lot of work too each time I enter a new country market, and I've to have thousands of suburb entered.

I've seen some Web Service a while ago which seems to be able to do the job (I can't remember the link). What is the best practice to list the suburbs dynamically based on the country selected?


Keep the master pairings in your database, but then push each country out to a JSON file (possibly on your CDN) that gets loaded dynamically and populates your select field whenever a country is chosen. Whenever you make a change in your database, re-push the respective JSON file.

0

精彩评论

暂无评论...
验证码 换一张
取 消