Jquery UI ---autocomplete的基本用法

客户端:

{% block scripts %}
 <script>
 $("#review").autocomplete({
   serviceUrl: '{{ search_reviewer_path() }}',
   minChars: 3,
   width: '200px',
   onSelect: function(value, data){
     $("#review").val(data.value);
     window.location.href = data.url;
   }
 });
 </script>
{% endblock %}

服务器端:


 /**
  * For the autocomplete function on the blacklist page
  */
 public function searchAction()
 {
   $query = trim($this->getRequest()->get('term'));
   $blacklists = BlacklistRepository::query($query, Blacklist::$SECTIONS);

   $results = array();
   foreach ($blacklists as $key => $blacklist) {
     $results[] = array(
       'label' => $blacklist->getName(),
       'url' => $this->generateUrl(
         'edit_blacklist',
         array('id' => $blacklist->getId())
       ),
       'value' => $blacklist->getName()
     );
   }

   return $this->renderJSONResponse($results);
 }


你可能感兴趣的:(jquery,UI,autocomplete,基本用法)