在jquery自动完成中获取值

这是我的代码

jquery代码

$("input#shopName").autocomplete({ source: "getShop.php", minLength: 2 }); 

从PHP返回的JSON值如下所示

 if(isset($_GET["term"])){ $query=$_GET["term"]; $result = $dataset->get_custom_record("SELECT * FROM mc_shop WHERE shop_title like '%" . $query . "%' ORDER BY id"); } while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $row_array['id'] = $row['id']; $row_array['value'] =$row['shop_title']; array_push($return_arr,$row_array); } echo json_encode($return_arr); 

自动完成工作正常,但从自动完成中选择值时,我需要将相应的“id”值放在一个隐藏变量中,我不知道该怎么办>

 $("input#shopName").autocomplete({ source: "getShop.php", minLength: 2, select: function(event, ui) { $("#theHidden").val(ui.item.id) } }); 

请参阅http://jqueryui.com/demos/autocomplete/#event-select

这对我很有用:

 $(ui)[0].item.label $(ui)[0].item.value