gpt4 book ai didi

jquery - 使用切片功能限制结果自动完成jquery ui

转载 作者:行者123 更新时间:2023-12-01 04:18:17 25 4
gpt4 key购买 nike

我需要限制此自动完成 jquery ui 脚本中的结果(最多 10 个)。我知道我必须使用切片函数,但我无法将其正确放置在脚本中。预先感谢您的帮助。

$(document).ready(function() {
var myArr = [];

$.ajax({
type: "GET",
url: "events.xml", // change to full path of file on server
dataType: "xml",
success: parseXml,
complete: setupAC,
failure: function(data) {
alert("XML File could not be found");
}
});

function parseXml(xml)
{
//find every query value
$(xml).find("topevent").each(function()
{
//you are going to create an array of objects
var thisItem = {};
thisItem['label'] = $(this).attr("label");
thisItem['value'] = $(this).attr("value");
myArr.push(thisItem);

});
}

function setupAC() {
$("input#searchBoxEv").autocomplete({
source: myArr,
minLength: 3,
select: function(event, ui) {
var urlString = "http://mysite.com/" + "eventi/" + (ui.item.value) + ".html";
$("input#searchBoxEv").val(urlString);
location.href=urlString;

}
});
}
});

最佳答案

$("#auto").autocomplete({
source: function(request, response) {
var results = $.ui.autocomplete.filter(myarray, request.term);

response(results.slice(0, 10));
}
});

您可以在这里找到更多文档..

http://jqueryui.com/autocomplete/

关于jquery - 使用切片功能限制结果自动完成jquery ui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12951773/

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