简体   繁体   English

单击下拉列表时,我需要填充一个表格。 哪个选项表现更好?

[英]I need to populate a form when I click on a dropdown. Which option is more performant?

I can either: 我可以:

-Get the information using AJAX, creating a request every time I click on the dropdown. -使用AJAX获取信息,每次我单击下拉列表时都会创建一个请求。

-Populate the form passing the information to div like this: -像这样填充将信息传递给div的表格:

@foreach($items as $item)
<div id="name_{{$item->id}}" value="{{$item->name}}"></div>
<div id="date_{{$item->id}}" value="{{$item->date}}"></div>
...
@endforeach

And then setting the value of the form with javascript, making a single request that extracts all the information and passing it to the site. 然后使用javascript设置表单的值,发出一个提取所有信息并将其传递到网站的请求。

I have already done both, but I would like to know which one would be the most performant. 我都做过,但是我想知道哪一个是性能最好的。

The answer is both, but depends on the case. 答案是两种,但要视情况而定。

For instance if you use the ajax method and the dropdown box is never pressed is better than the passing the values. 例如,如果您使用ajax方法,并且从不单击下拉框比传递值更好。

If the dropdown box is hit once or more than once, the second method will be better. 如果下拉框被单击一次或多次,则第二种方法会更好。 But you will have also a downside: you'll not get the newest version of the dropdown box information from where ever you get it. 但是您也有一个缺点:无论您从哪里获得下拉框信息的最新版本。

暂无
暂无

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

相关问题 当超过 1 个 div append 时,我从 DB 检索的下拉选项会增加 - When more than 1 div append, the dropdown option increases which I retrieve from DB 弄乱动态下拉菜单。 我究竟做错了什么? - Messing up the dynamic dropdown. What am I doing wrong? 如何添加一个下拉菜单,当您 select 一个选项并单击发送时,它会显示 email 中的选项? - How do I add a dropdown menu that when you select an option and click send it shows the option in the email? 当用户单击slick-header-menuitem下拉列表时,如何将所有数据放入slickgrid。 - How to get all the data into the slickgrid when user click on the slick-header-menuitem dropdown.? 我如何才能使此for循环更高效 - How can I make this for loop more performant 单击外部下拉菜单时关闭下拉菜单 - Close Dropdown when I click outside dropdown 单击“编辑”按钮时,如何用数据库值填充HTML表单? - How do I populate HTML form with database values when I click edit button? 我的目标是写一个条件,如果我点击“卡 1”,我需要填充与公共属性匹配的 arr2 的值 - My objective is to write a condition as If I click on 'Card 1' I need to populate value of arr2 which matches with common property 如何使用jQuery单击和选项并让它填充一个字段 - How do I use jQuery to click and option and have it populate a field 当我只单击其中一个问题时,我需要帮助禁用其他问题的下拉样式 - I need HELP in disabling dropdown styles for other questions when I click on just one of them
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM