【发布时间】:2015-08-02 18:01:30
【问题描述】:
我一直在互联网上和 stackoverflow 网站上搜索这个,但似乎找不到我一直在寻找的解决方案。
我正在尝试实现分类搜索栏,并且我在 _renderMenu 方法中调用了覆盖的 _renderItem 方法,但它不起作用!
以下是我的代码:
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 方法吗?
【问题讨论】:
标签: javascript jquery search autocomplete