Grouping results in JQuery UI Autocomplete plugin?

前端 未结 4 2056
故里飘歌
故里飘歌 2021-01-03 07:30

I\'m trying to create some search functionality across several types of data, with autocomplete. I\'d prefer to have custom views for each autocomplete suggestion, as well a

4条回答
  •  遥遥无期
    2021-01-03 08:05

    This is the accepted answer by @natedavisolds updated for use with Jquery UI 1.10.

      $.widget("custom.catcomplete", $.ui.autocomplete, {
        _renderMenu: function( ul, items ) {
          var that = this;
          var currentCategory = "";
          $.each( items, function( index, item ) {
            if (item.category != currentCategory) {
              $('
  • ').addClass('ui-autocomplete-category').html(convert_category(item.category)).appendTo(ul); currentCategory = item.category; } that._renderItemData( ul, item ); }); } });
提交回复
热议问题