jQuery分类自动填充搜索

时间:2015-05-21 07:39:59

标签: javascript jquery search autocomplete

我一直在网上和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方法?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案!

我只需要将_renderItem方法更改为以下内容:

categorySearch._renderItem

相关问题