简体   繁体   English

AngularJS-在表中使用指令-ng-repeat影响性能

[英]AngularJS - Using directive within table - ng-repeat impacting the performance

I am using a directive to display a drop-down with 9-10 options in each row of a table. 我正在使用指令在表的每一行中显示包含9-10个选项的下拉列表。 This table may have upto 200 rows. 该表最多可包含200行。 My concern is, that directive is getting called 200 times for each row. 我担心的是,该指令每行被调用200次。 is there any way which can create drop-down just once and simply insert in each row and bind it with the scope so if there is any event on drop-down then that also work fine 有什么方法可以只创建一次下拉菜单,只需插入每行并将其与范围绑定,因此如果下拉菜单上有任何事件,那也可以正常工作

If it were me, I wouldn't worry about it unless you're seeing noticeable issues with performance. 如果是我,除非您发现明显的性能问题,否则我不会担心。 Most browsers should be able to handle a 200 row table with directives in every row without any problem. 大多数浏览器应该能够处理200行表,并且每行都带有指令,而不会出现任何问题。

However, if you're concerned about it or if you're seeing issues, you have a couple of options. 但是,如果您对此感到担心或遇到问题,则有两种选择。

1) Instead of a dropdown menu in each row, just put an "edit" button and use that to open a modal where the user selects what they want 1)而不是在每一行中都有一个下拉菜单,只需放置一个“编辑”按钮,并使用它来打开一个模式,用户可以在其中选择所需的内容

2) Use an editable table plugin like ui-grid (double click the example table's data to edit). 2)使用可编辑表格插件,例如ui-grid (双击示例表格的数据进行编辑)。 It has been tested with thousands of rows and it performs well. 它已经过数千行的测试,并且性能良好。 In the example you'll see a dropdown menu where the user can select Male or Female - that could be configured to have the options you need. 在示例中,您将看到一个下拉菜单,用户可以在其中选择“男性”或“女性”-可以将其配置为具有所需的选项。

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

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