我在现有项目上使用Jquery UI自动完成。好了,表现狗缓慢,执行缓存Jquery UI自动完成Combobox
input.autocomplete("search", "");
我的解决办法是缓存中的信息尤其是当,所以即使它的狗慢只发生一次。我想我错过了一个非常简单的Javascript错误,我真的很感谢一些帮助追逐它。
下面是代码
input.autocomplete(
{
delay: 0,
minLength: 0,
source: function (request, response)
{
if (request.term in cache)
{
response(cache[request.term]);
return;
}
// The source of the auto-complete is a function that returns all the select element's child option elements.
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
response(select.children("option").map(function()
{
var text = $(this).text();
if (this.value && (!request.term || matcher.test(text)))
{
cache[request.term] = text;
return { label: text, value: text, option: this };
}
}));
},
select: function (event, ui)
{
// On the select event, trigger the "selected" event with the selected option. Also update the select element
// so it's selected option is the same.
ui.item.option.selected = true;
self._trigger("selected", event,
{
item: ui.item.option
});
},
change: function (event, ui)
{
// On the change event, reset to the last selection since it didn't match anything.
if (!ui.item)
{
$(this).val(select.children("option[selected]").text());
return false;
}
}
});
// Add a combo-box button on the right side of the input box. It is the same height as the adjacent input element.
var autocompleteButton = $("<button type='button' />");
autocompleteButton.attr("tabIndex", -1)
.attr("title", "Show All Items")
.addClass("ComboboxButton")
.insertAfter(input)
.height(input.outerHeight())
.append($("<span />"))
autocompleteButton.click(function()
{
// If the menu is already open, close it.
if (input.autocomplete("widget").is(":visible"))
{
input.autocomplete("close");
return;
}
// Pass an empty string as value to search for -- this will display all results.
input.autocomplete("search", "");
input.focus();
});
几乎所有的它与我的软弱缓存的尝试之外默认jQuery UI的组合框的示例代码。它将返回下拉菜单中的每个字符。
例如,如果返回的解集是乌合之众,和下一个被取得foobar“缓存数据”将如下所示 ˚F ö ö b 一个 ř 每个在其自己的行
我需要它是 乌兹别克人 foobar
这将是非常好的,如果这也适用于一个空字符串,因为这是我最困难的调用。
感谢您的帮助
我们在这里是一个.net商店,所以服务器端是C# – Aardvark 2010-09-02 22:56:49
有几种方法可以解决这个问题。我发现的最好方法是简单地缓存整个结果集并在一段时间后过期。它的每一个后续查询都会违背缓存。 – 2010-09-03 16:55:25