2017-05-19 59 views
0

我正在爲文本框的自動完成功能工作,並且需要同時獲取十個結果,並且有一個選項可以獲得更多超鏈接。目前它獲取所有結果。JQuery自動完成文本框asp.net限制結果

我的代碼到目前爲止附在下面。你能提供指導嗎?

$(document).ready(function(){ 
      $('#<%=txtEmployeeName.ClientID%>').autocomplete({ 
       source: function (request, response) { 
        $("#loading").show(); 
        $.ajax({ 
         type: "POST", 
         contentType: "application/json; charset=utf-8", 
         url: "AccountDisclosureSearch.aspx/SearchEmpByText", 
         data: "{ 'empName':'" + request.term + "'}", 
         dataType: "json", 
         success: function (data) { 
          response($.map(data.d, function (item) { 
           return { 
            label: item.split(";")[0], 
            val: item.split(";")[1] 
           // name: item.split("|")[0] 
           } 
          })) 
          $("#loading").hide(); 
         }, 

         error: function (response) { 
          alert(response.responseText); 
          $("#loading").hide(); 
         } 
        }); 
       }, 
       select: function (e, i) { 

       // $("#<%=hempid.ClientID %>").val(i.item.val); 
        storeEmployee(i.item.label, 0, i.item.val); 

       }, 

       open: function(){ 
       $('.ui-autocomplete').css('width', '220px'); 
       }, 
       minLength: 3 

      }); 
     }); 
+0

在你的後臺查詢,您可以設置限制像LIMIT 0,10 – lalithkumar

+0

@stackoverflkowfan你有訪問AccountDisclosureSearch.aspx可能是的,你可以在JSON響應中添加一個額外的項目,以便自動添加所需的元素.. –

回答

0

可以使用maxResultsmaxShowItems象下面這樣:

$(document).ready(function(){ 
      $('#<%=txtEmployeeName.ClientID%>').autocomplete({ 
      maxResults:10, 
      or 
      maxShowItems:10, 
      or 
      maxHeight: 150, 
      source: function (request, response) { 
      //whatever you have 
      } 
      }); 
}); 

有關更多信息,請Here

+0

謝謝Lalit,但我也需要一個hypoerlink在底部顯示剩餘的或下一個10 ...我掙扎着那 – stackoverflkowfan

+0

是否需要你使用超鏈接?否則你可以使用帶滾動條的maxHeight – lalithkumar

+0

我可以嘗試maxheight,但是超鏈接是原始需求:) – stackoverflkowfan