当用户开始在搜索框上键入时,建议页面将返回与该nama匹配的所有集合中的最新项目以及其他数据.
我想显示该项目(沿着其图像),以及"查看此集合中的所有项目"的链接.
我可以通过以下代码完成(大部分):
$('#search').autocomplete({
source: function (request, response) {
$.ajax({
url: suggesturl,
dataType: 'json',
data: request,
success: function (data) {
response(data.map(function (value) {
return {
'label': '<img src="' + value.thumbsmall + '" />' + value.name + '<a href="/">More items from this collection...</a>',
'value': value.fullname
};
}));
}
});
},
minLength: 3
})
Run Code Online (Sandbox Code Playgroud)
问题是,虽然链接出现在框中,但当它被单击时,它会被忽略,并执行默认select操作(项目value被放入文本框).