[英]jQuery categorized autocomplete search
我一直在互联网和stackoverflow网站上进行搜索,但是似乎找不到我一直在寻找的解决方案。
我想实现分类的搜索栏,我有被覆盖的_renderItem
方法里面调用_renderMenu
方法,但它不工作!
以下是我的代码:
var categorySearch = $("#searchfield").autocomplete({}).data('ui-autocomplete');
_renderItem = function(ul, item) {
return $('<li>')
.data('item.autocomplete', item)
.append("<a>"+"<img src ='/account/"+item.id+"/icon/logo' onerror='$(this).hide()' style='width:40px;height:40px;border-radius:50px' alt=''/>" + " " + " " +item.label+"</a>")
.appendTo(ul);
};
categorySearch._renderMenu = function(ul, items){
var that = this;
currentCategory = " ";
$.each( items, function( index, item ) {
if(item.category !== currentCategory) {
ul.append("<li><strong>" +item.category +"</strong></li>");
currentCategory = item.category;
}
that._renderItem(ul, item);
});
};
一切工作正常,除了我的_renderItem
方法未实现。 还有其他方法可以调用重写的renderItem方法吗?
我找到了解决方案!
我只需要将_renderItem
方法更改为以下内容:
categorySearch._renderItem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.