gpt4 book ai didi

javascript - 触发器 ('click' ) 导致 “Script is running slowly, do you want to stop it?"

转载 作者:可可西里 更新时间:2023-11-01 13:35:51 24 4
gpt4 key购买 nike

我有一个像这样的 TreeView 表:http://jsfiddle.net/NPGUx/6/我正在使用:

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

要隐藏加载的所有元素,问题是我有太多行(如 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-->

Demo

关于javascript - 触发器 ('click' ) 导致 “Script is running slowly, do you want to stop it?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16578015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com