[英]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.