由于我看不到您的代码,我们假设这[{"title":"some-title","link":"/searc?q=some-title"}, {"title":"some-title2","link":"/searc?q=some-title2"}]
是您的数据源。话虽这么说,这就是我将如何去做......
$(document).ready(function(){
var dataSource= [{"title":"some-title","link":"/searc?q=some-title"}, {"title":"some-title2","link":"/searc?q=some-title2"}];
$('#search-field').autocomplete({
source: function(request, response) {
var filterResults = $.map(dataSource, function(item) {
if(item.title.toLowerCase().indexOf(request.term.toLowerCase()) != -1 || item.link.toLowerCase().indexOf(request.term.toLowerCase()) != -1){
return item;
}
else{
return null;
}
});
response(filterResults);
}
}).data('autocomplete')._renderItem = function (ul, item)
{
return $("<li></li>")
.data("item.autocomplete", item)
.append($("<a></a>").html("Title: " + item.title + ", Link: " + item.link))
.appendTo(ul);
};
});
现场演示:http: //jsfiddle.net/hUE9M/131/
使用这种方法,您可以搜索“标题”和“链接”属性。我希望这有帮助!