2017-10-09 2 views
0

난 다음 JQuery와 있습니다JQuery와 스크롤 자동 완성 - 감지 하단

$("#input-name").autocomplete({ 
         source: function(request, response) { 
          if (!names.length){ 
           names = [NoResultsLabel]; 
          } 
          response(names); 
         }, 
         select: function (event, ui) { 
          if (ui.item.label === NoResultsLabel) { 
           event.preventDefault(); 
          } 
          for(var i=0;i<data.schools.length;i++){ 
           if(ui.item.label == names[i]){ 
            document.getElementById('filter[id]').value = ids[i]; 
            i = data.schools.length; 
           } 
          } 
         }, 
         focus: function (event, ui) { 
          if (ui.item.label === NoResultsLabel) { 
           event.preventDefault(); 
          } 
         } 
        }); 

내가 그것을 스크롤 할 수 있도록하기 위해 CSS를 추가 :

<style> 
    .ui-autocomplete { 
     max-height: 100px; 
     overflow-y: auto; 
     overflow-x: hidden; 
    } 
    .ui-state-focus { 
     font-weight: normal; 
    } 
</style> 

와 나는 사용자가 아래로 스크롤 할 때 감지 할 동일한 이름과 일치하는 행이 너무 많기 때문에 Ajax 요청을 실행합니다. (이름에서 학교를 검색하고 공동 ID를 반환하는 선택 메신저

시도했습니다.

jQuery(function($) { 
      $('.ui-autocomplete').on('scroll', function() { 
       if($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) { 
        requests++; 
        getSchools(); 
       } 
      }) 
     }); 

하지만 난 잘못 무엇인지 발견

답변

0

가 작동하지 않습니다, 그것은, 내가이

$("selector").autocomplete("widget").scroll(function(){ 
        ... 
       }); 

을 workaraound하지만 자동 완성이

를 초기화 한 후에 만이 함수를 호출 선택기 발견