2011-08-31 91 views
0

我目前使用jquery-ui-1.8.10 我正在使用自動完成組件,並且無法在文檔中找到任何方式來將其配置爲將超過10個結果返回給即使列表中有超過10個從服務器返回的結果。 http://jqueryui.com/demos/autocomplete/jQueryUI自動完成不會向用戶顯示超過10個結果

這是一個類似的帖子,但max對我不起作用,感覺就像他使用jQueryUI中自動完成的另一個組件,儘管他說他是。 jQuery autocomplete won't show more than 10 results

如何配置組件以向用戶顯示超過10個結果?

$("#module-name-search").autocomplete({ 
     source: "service/searchForModule?langCode=" + langCode, 
     minLength: 3, 
     max: 50, 
     select: function(event, ui){ 
      $("#module-code-search").val(ui.item.id); 
      $("#module-name-search").val(ui.item.text); 

      return false; 
     } 
    }).data("autocomplete")._renderItem = function(ul, item){ 
     return $("<li></li>").data("item.autocomplete", item).append("<a style='font-size:9px;'>" + item.text + "</a>").appendTo(ul); 
    }; 
+2

如果您不重寫_renderItem函數,它會工作嗎?如果將minLength設置爲0,那麼將JS控制檯拉起來並執行$(「#module-name-search」)。autocomplete。(「search」),你還看到只有10個結果嗎? – spike

+0

我現在還沒有編碼,只能再次進入堆棧溢出。當有人回覆時,試着設置它給我發電子郵件。我確實發現了一個修補程序,它將搜索代碼併發布更新。 – avanderw

回答

0

我找到了我的問題的解決方案...下面發佈的是代碼。

$("#module-name-search").autocomplete({ 
     source: function(request, response) { 
      if (searchAjax != null) { 
      searchAjax.abort(); 
     } 
     searchAjax = $.ajax({ 
       url: "service/searchForModule?langCode=" + langCode, 
       dataType: "json", 
       data: { 
        term: encodeURI(request.term), 
        iTipeProgram: $("#prog-type-input").val() 
       }, 
       success: function(data) { 
        //alert(data); 
        response(data); 
       } 
      }); 
     }, 
     minLength: 3, 
     select: function(event, ui){ 
      $("#module-code-search").val(ui.item.id); 
      $("#module-name-search").val(ui.item.text); 

      return false; 
     }, 
     open: function() { 
      $(this).removeClass("ui-corner-all").addClass("ui-corner-top"); 
     }, 
     close: function() { 
      $(this).removeClass("ui-corner-top").addClass("ui-corner-all"); 
     } 
    }).data("autocomplete")._renderItem = function(ul, item){ 
     return $("<li></li>").data("item.autocomplete", item).append("<a style='font-size:9px;'>" + item.text + "</a>").appendTo(ul); 
    };