【问题标题】:2,000+ jQuery UI autocomplete combobox throws stopped responding error2,000+ jQuery UI 自动完成组合框抛出停止响应错误
【发布时间】:2011-05-04 00:45:06
【问题描述】:

只是想确认我已经超出了 jQuery UI 自动完成组合框的实际限制,我在 FF 中收到以下错误:

此页面上的脚本可能正忙,或者 它可能已停止响应。你 现在可以停止脚本,打开 调试器中的脚本,或者让 脚本继续。

该页面是一个由 php 生成的大表(2000 多行),每行将包含 7 个这些组合框(7 列),但是我几乎无法通过集合的第一列。该页面将加载并运行,但需要几分钟,并且浏览器会在一段时间内无响应。

有没有办法改变 JS 以提高效率?下面是一个 JS 示例,我使用 php 将数组插入到脚本中(第 3 行)。

代码:

            <script type='text/javascript'>
  var input = new Array();
var i = 1;
<?php echo $JSElements; ?> //PHP
$('.TC_1').each(function(index) {

input[i] = $("[name=TC_"+i+"_1]").autocomplete({
    source: elementArray,
    select: function(){alert("selected");},
    minLength: 0
}).addClass("ui-widget ui-widget-content ui-corner-left");

//Get the id for the target field:
    var target = $(input[i]).attr('name');
    var ID = target.substr(3);

$("<button id='bt_"+ID+"' type='button'>&nbsp;</button>")
    .attr("tabIndex", -1)
    .attr("title", "Show All Items")
    .insertAfter(input[i])
    .button({
        icons: {
            primary: "ui-icon-triangle-1-s"
        },
        text: false
    })
    .removeClass("ui-corner-all")
    .addClass("ui-corner-right ui-button-icon")
    .click(function() {

        // close if already visible
        if ($("[name=TC_"+ID+"]").autocomplete("widget").is(":visible")) {
        $("[name=TC_"+ID+"]").autocomplete( "close" );
             return;
        }
        $(this).blur();
        $("[name=TC_"+ID+"]").autocomplete("search", "" );
        $("[name=TC_"+ID+"]").focus();
    });
    i++;
});
  </script>

如果没有办法让它工作?任何人都可以提出任何替代方案吗?请记住,可能会有大约 8,000 个字段!如果没有,我最后的办法是自定义构建一个简单的 ajax 下拉菜单。

【问题讨论】:

    标签: jquery user-interface autocomplete combobox


    【解决方案1】:

    当前版本的 jQuery 自动完成插件实际上会接受一个 URL,这使得 Ajaxy 非常容易启动和运行。

    See here

    【讨论】:

    • 是的,我想,但你不认为我试图创建的这些人的数量会导致加载时间过长吗?我的工作方式是遍历文本字段,将它们转换为组合框并创建一个唯一的相应按钮。
    • 但是ajax版本的优点是可以在服务器端过滤结果,然后再发送到浏览器。当进行 ajax 调用时,它将在查询字符串上传递文本框的当前内容,以便您可以剔除绝大多数结果。这是假设服务器端还没有性能问题;-)
    猜你喜欢
    • 1970-01-01
    • 2011-04-07
    • 2011-11-16
    • 1970-01-01
    • 2013-09-14
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多