If I have a array of objects like
var arrLinks = [
{ key: 1, url: "http://google.com" },
{ key: 2, url: "http://yahoo.com", title: "Yahoo" },
{ key: 2, url: "http://microsoft.com" }
];
Can I use it as the source for autocomplete? I tried implementing in following http://jqueryui.com/demos/autocomplete/#custom-data but didn't get it http://jsfiddle.net/mvNNj/
You need to:
1 - Actually include jQuery + UI on your test page.
2 - Incorporate the use of 'labels' which the Autocompleter uses to find matches:
$(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With