【问题标题】:jQuery categorized autocomplete searchjQuery 分类自动完成搜索
【发布时间】: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


    【解决方案1】:

    我找到了解决办法!

    我只需将我的_renderItem 方法更改为如下:

    categorySearch._renderItem

    【讨论】:

      猜你喜欢
      • 2013-08-20
      • 1970-01-01
      • 2017-05-17
      • 1970-01-01
      • 2015-08-18
      • 2019-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多