jQuery UI Autocomplete:仅返回使用输入作为前缀的字符串

时间:2010-11-13 11:04:45

标签: jquery-ui jquery-ui-autocomplete

我正在使用jQuery Autocomplete 1.8。每次返回包含输入的每个字符串作为子字符串。如何让它只返回包含输入的字符串作为前缀?

1 个答案:

答案 0 :(得分:1)

我在sql中这样做。我正在使用php生成json

<?php
set_include_path(get_include_path() . ':' . '/home/lms/library/php');
set_include_path(get_include_path() . ':' . '/home/lms/systems/ORM');
require_once("Configuration.php");
require_once("DALI_Class.php");

//$unitID = $_POST['unitID'];
$unitID = $_GET["term"];
$return_array=array();
$row_array=array();
$lmsAdminSysDB = DALI::connect(LMS_MIDDLEWARE_DATABASE);

$selectUnit = "SELECT " . 
                "UnitID, " . 
                "Title " . 
                "FROM UnitTBL " . 
                "WHERE UnitID LIKE '".$unitID."%' " .                 
                "ORDER BY UnitID " . 
                ""; 

$resultUnit = $lmsAdminSysDB->Execute($selectUnit);

while($row = $resultUnit->FetchRow()) {
   $row_array['label'] = $row['UnitID']." - ".$row['Title'];
   $row_array['value'] = $row['UnitID'];
   $row_array['title'] = $row['Title'];
   array_push($return_array,$row_array);

 }
unset($resultUnit);

//header('Content-type: application/json');
//echo json_encode($result);
DALI::disconnect($lmsAdminSysDB);
echo json_encode($return_array);
?>