我想顯示顯示像 街道名稱>城市>國家(4個不同的varaibles街道,城市,國家,網址,我在JSON從服務器獲取) ,當我選擇的話,會轉到URL像一個鏈接 並突出顯示我在建議中找到的字母 我該怎麼辦? 這裏是我的代碼如何使用jquery UI自動完成1.8.4?
<script type="text/javascript">
$('#search').autocomplete({
source: function(req, add){
//pass request to server
$.getJSON("suggest.php?callback=?", req, function(data) {
//create array for response objects
var suggestions = [];
//process response
$.each(data, function(i, val){
suggestions.push(val.lable+' '+val.value+' '+val.both);
});
//pass array to callback
add(suggestions);
});
},
select: function(e, ui) {
$('#search').val(ui.item.lable);
},
width: 300,
max: 10,
delay: 50,
minLength: 1,
scroll: false,
highlightItem: true
});
</script>
服務器響應
([{"lable":"apartamentos mojácar beach","value":"mojacar","both":"spain"},{"lable":"hotel mandakini grand","value":"new delhi","both":"india"},{"lable":"hotel sol y mar sharming inn","value":"sharm el sheikh","both":"egypt"},{"lable":"la quinta inn and suites sarasota","value":"sarasota","both":"usa"},{"lable":"ocean sand golf and beach resort","value":"punta cana","both":"dominican republic"},{"lable":"rooms barcelona","value":"barcelona","both":"spain"},{"lable":"villa maroc essaouira","value":"essaouira","both":"morocco"},{"lable":" il casale farmhouse with panoramic swimming poo","value":"bettona","both":"italy"},{"lable":" shelley's ","value":"lynton","both":"united kingdom"},{"lable":" 1 melrose blvd by seasons in africa","value":"johannesburg","both":"south africa"}]);
我知道問題是出在「選擇」和autocomple的「來源」字段,但我不知道如何使用它。 如何解析響應,使其可以工作。它只有一個領域工作,但不是4場商(VAR)
//////////////////////
確定現在我可以得到3來自服務器的惡意軟件,我將它們添加到源代碼中。 但我不能只選擇一個它選擇所有的字符串! 我該如何管理?
我將編輯問題 – Ben 2010-09-12 15:55:24
你的「答案」應該是對問題的評論。 – 2010-09-12 16:03:05
我添加服務器回答這個問題。 – Ben 2010-09-12 16:03:12