gpt4 book ai didi

jquery - 如何使用对象数组作为 jQuery UI AutoComplete 的源

转载 作者:行者123 更新时间:2023-12-03 22:14:54 27 4
gpt4 key购买 nike

如果我有一个像这样的对象数组

var arrLinks = [
{ key: 1, url: "http://google.com" },
{ key: 2, url: "http://yahoo.com", title: "Yahoo" },
{ key: 2, url: "http://microsoft.com" }
];

我可以使用它作为自动完成的来源吗?我尝试在以下 http://jqueryui.com/demos/autocomplete/#custom-data 中实现但没得到http://jsfiddle.net/mvNNj/

最佳答案

您需要:

1 - 实际上在您的测试页面上包含 jQuery + UI。

2 - 合并自动完成程序用来查找匹配项的“标签”的使用:

$(function() {
var arrLinks = [
{
key: 1,
url: "http://google.com",
label: 'google'},
{
key: 2,
url: "http://yahoo.com",
title: "Yahoo",
label: 'yahoo'},
{
key: 2,
url: "http://microsoft.com",
label: 'microsoft'}
];
$("input[name=url]").autocomplete({
source: arrLinks
}).data("autocomplete")._renderItem = function(ul, item) {
return $("<li>").data("item.autocomplete", item).append("<a>" + item.url + "</a>").appendTo(ul);
};
});

Your test page, working.

关于jquery - 如何使用对象数组作为 jQuery UI AutoComplete 的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4668206/

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