【发布时间】:2010-09-13 02:03:39
【问题描述】:
我想显示类似的建议 STREET NAME > CITY > COUNTRY (我从服务器获取的 json 中的 4 个不同的变量街道、城市、国家、网址) 当我选择一个时,它会像链接一样转到 url 并将突出显示我在建议中找到的字母 我该怎么做? 这是我的代码
<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"}]);
我知道问题出在自动完成的“SELECT”和“SOURCE”字段中,但我不知道如何使用它。 如何解析响应以便它可以工作。它仅适用于一个字段,但不适用于 4 个字段(vars)
////////////////////
好的,现在我可以从服务器获取 3 个病毒,我将它们添加到源代码中。 但我不能一直只选择一个,它会选择所有字符串! 我该怎么办?
【问题讨论】:
标签: javascript jquery user-interface autocomplete