0

http://jqueryui.com/autocomplete/#categoriesのように Autocomplete ウィジェットの検索結果にカテゴリを追加したいのですが、コードを以下の作業コードに統合する方法がわかりません。

    <script> 
        $(function() {
            function split( val ) {
              return val.split( /,\s*/ );
            }
            function extractLast( term ) {
              return split( term ).pop();
            }

            $( "#search" )
              // don't navigate away from the field on tab when selecting an item
              .bind( "keydown", function( event ) {
                if ( event.keyCode === $.ui.keyCode.TAB &&
                    $( this ).data( "ui-autocomplete" ).menu.active ) {
                  event.preventDefault();
                }
              })
              .autocomplete({
                source: function( request, response ) {
                    console.log(request);
                    console.log(response);
                    console.log(extractLast(request.term));
                  $.getJSON( "http://192.168.33.10/app_dev.php/search/query/" + extractLast( request.term ), {
                    term: extractLast( request.term )
                  }, response );
                },
                search: function() {
                  // custom minLength
                  var term = extractLast( this.value );
                  if ( term.length < 2 ) {
                    return false;
                  }
                },
                focus: function() {
                  // prevent value inserted on focus
                  return false;
                },
                select: function( event, ui ) {
                    window.location = ("http://192.168.33.10/" + ui.item.link);
                }
              });
        });
    </script>

    <div class="ui-widget">
        <label for="search">Search</label>
        <input type="text" id="search" />
    </div>
4

1 に答える 1