通过水平规则分离jQuery自动完成结果

时间:2014-05-09 20:03:10

标签: php jquery

所以我有这个脚本用于搜索db的结果。由于所有结果都出现了,并且它们混淆了,有没有可能通过水平规则将结果分开? 欢迎任何建议。

代码: -

JS

<script>
  $(function() {
    function log( message ) {
      $( "<div>" ).text( message ).prependTo( "#log" );
      $( "#log" ).scrollTop( 0 );
    }

    $( "#birds" ).autocomplete({
      source: "search.php",
      minLength: 2,
      select: function( event, ui ) {


        log( ui.item ? "Selected: " + ui.item.value + " aka " + ui.item.label :
          "Nothing selected, input was " + this.actor );
         window.location.href = './products/' + ui.item.productid;
         //window.location.href = 'product_display.php?id=' + ui.item.value;
       // document.testForm.action = "pretravel.php?id="+ui.item.value;
        //document.testForm.submit();
      }
    });
  });



  </script>

的search.php

<?php
include 'dbconnector.php';

// Sanitise GET var
if(isset($_GET['term']))
{
$term = mysql_real_escape_string($_GET['term']);
// Add WHERE clause
//$term="Apple";
$query = "SELECT `productid`, `productname` FROM `products` WHERE `productname` LIKE '%".$term."%' ORDER BY `productid`";


$result = mysql_query($query,$db) or die (mysql_error($db));
$id=0;
$return=array();
while($row = mysql_fetch_array($result)){

    //array_push($return,array('label'=>$row['productid'],'actor'=>$row['productname']));
    //array_push($return,array('value'=>$row['productid'],'label'=>$row['productname']));
    //array_push($return,array('actor'=>$row['productname'],'label'=>$row['productid']));
    array_push($return,array('productid'=>$row['productid'],'label'=>$row['productname']));

}

header('Content-type: application/json');
echo json_encode($return);
//var_dump($return);

exit(); // AJAX call, we don't want anything carrying on here
}
else
{
    header('Location:index');
}

?>

1 个答案:

答案 0 :(得分:0)

创建自己的_renderItem callback function

或者只使用CSS来模拟一个:

.ui-menu-item: { border-bottom: 1px solid black; }