2014-01-08 3 views
0

를 필터링 할 수 없습니다. 예 : 30을 입력하면 30으로 시작하는 결과 만 표시됩니다. 그러나 내 코드는 모든 결과를 보여줍니다.Grails에 JQuery와 아약스 자동 완성 내가 JQuery와 아약스 자동 완성 기능이 튜토리얼에 따라 Grails는 뭐하는 거지 검색 결과

코드는 다음과 같습니다

$('#sitePostCode').autocomplete({ 
     source: function (request, response) { 
      $.ajax({ 
       url: getPostcodeValidateUrl(), 
       dataType: "json", 
       data: { 
        maxRows: 12, 
        name_startsWith: request.term 
       }, 
       success: function (data) { 
        response($.map(data, function (item) { 
         return { 
          label: item.postCode, 
          value: item.postCode 
         } 
        })); 
       } 
      }); 
     }, 
     minLength: 2, 
     select: function (event, ui) { 
      $('#sitePostCode').val(ui.item.value) 
     } 
    }); 
+0

작업에 "maxRows : 12"를 사용 했습니까? – Abs

답변

0

이 시도 ....

<!doctype html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<title>jQuery UI Autocomplete - Remote JSON datasource</title> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"> 
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
<link rel="stylesheet" href="/resources/demos/style.css"> 
<r:script> 
    $(function() { 
     function log(message) { 
      $("<div>").text(message).prependTo("#log"); 
      $("#log").scrollTop(0); 
     } 
     $("#book").autocomplete({ 
      source: function(request, response) { 
       $.ajax({ 
        url: "${createLink(controller: 'book', action: 'test')}", 
        dataType: "json", 
        data: { 
         maxRows: 12, 
         name_startsWith: request.term 
        }, 
        success: function(data) { 
         response($.map(data, function(item) { 
          return { 
           label: item.title, 

           value: item.title 
          } 
         })); 
        } 
       }); 
      }, 
      minLength: 2 
     }); 
    }); 
</r:script> 
<r:layoutResources /> 
</head> 
<body> 
<div class="ui-widget"> 
<label for="book">Your Book: </label> 
<input id="book"> 
</div> 
<r:layoutResources /> 
</body> 
</html> 

그리고 난 그냥 한 콘트롤러 측에서

는 것을 :

def test() { 
    def bookInstanceList = Book.createCriteria().list([max: params.maxRows]) { 
     and{ 
      ilike('title', "%${params.name_startsWith}%") 
     } 
    } 
    render bookInstanceList as JSON 
} 

은 위에서 작동 내 측면.