简体   繁体   English

高效填充下拉列表:Javascript vs数据库(Mysql-Django)

[英]Efficiently Populating Dropdown List: Javascript vs Database (Mysql-Django)

I want to have 3 dropdown lists going like 我想有3个下拉列表

Select:State 选择:州
Select City 选择城市
Select: Restaurant 选择:餐厅

When the first dropdown list has an item selected, the "Select City" list is updated, and when the second dropdown list has an item selected, the last one is updated. 当第一个下拉列表中有一个项目被选中时,“选择城市”列表被更新,而第二个下拉列表中一个项目被选择时,最后一个列表被更新。

I am stuck between 3 approaches: 我陷入3种方法之间:

  1. Using Javascript to put in all possible values. 使用Javascript输入所有可能的值。 And using form onchange to invoke the update method. 并使用form onchange调用update方法。
  2. Prepopulate dropdown from database (MySQL). 从数据库(MySQL)预填充下拉列表。
  3. A hybrid of the first two - first 2 with Jscript, last one from database. 前两个的混合-前两个与Jscript,最后一个来自数据库。

Now how does the performance and pros/cons of each approach for hosting, VPS and PAAS compare? 现在,如何比较托管,VPS和PAAS每种方法的性能和优缺点?

For the sake of usability I would update the select boxes using Ajax calls. 为了方便起见,我将使用Ajax调用更新选择框。

Another benefit from choosing this approach would be that your application logic is mostly kept server side, which in most cases is easier to write tests for. 选择这种方法的另一个好处是,您的应用程序逻辑大部分保留在服务器端,这在大多数情况下更易于编写测试。

You could populate the first select box by querying in your view and passing the results down to your template. 您可以通过在视图中查询并将结果向下传递到模板来填充第一个选择框。 If you disable the other 2 select boxes you can active/populate them after the 1 one is selected through an ajax call. 如果禁用其他2个选择框,则可以在通过ajax调用选择1个选择框之后激活/填充它们。

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

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