触发('click')导致“脚本运行缓慢,是否要停止它?”

trigger('click') cause “Script is running slowly, do you want to stop it?"

本文关键字:是否 脚本 click 导致 运行 触发 缓慢      更新时间:2023-09-26

我有一个像这样的树视图表:http://jsfiddle.net/NPGUx/6/和我使用:

$('.toggle').trigger('click');

隐藏所有元素onload,问题是我有太多的行(如1000-1500),所以导致消息"脚本运行缓慢,你想停止它吗?"出现了三次。

如何更好地隐藏所有元素?

这个怎么样:-

在呈现记录时将类从折叠更改为展开,并在最后使用此查询,以隐藏除第0层外的所有内容,或在呈现自身时隐藏所有其他级别的tr。

脚本

 $('tr[data-depth]').not('[data-depth=0]').hide(); // Or just render all tr's but this
      //with display:none css property.

更改过滤器以避免从所有tr中过滤:-

      var rootDepth = $(this).closest('tr').data('depth');
      var findChildren = function (tr) {
        var depth = tr.data('depth');
        return tr.nextUntil('[data-depth=' + rootDepth + ']').filter(function(){
          return $(this).data('depth') > depth;
        });

Html

 <tr data-depth="0" class="expand level0"> <!--Instead of collapse-->
    <td><span class="toggle expand"></span>Item 1</td> <!--Instead of collapse-->
演示