0
我想向自動填充小部件的搜索結果中添加類別,例如http://jqueryui.com/autocomplete/#categories,但我無法弄清楚如何將代碼集成到下面的工作代碼中。自動完成Jquery UI集成的類別
<script>
$(function() {
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$("#search")
// don't navigate away from the field on tab when selecting an item
.bind("keydown", function(event) {
if (event.keyCode === $.ui.keyCode.TAB &&
$(this).data("ui-autocomplete").menu.active) {
event.preventDefault();
}
})
.autocomplete({
source: function(request, response) {
console.log(request);
console.log(response);
console.log(extractLast(request.term));
$.getJSON("http://192.168.33.10/app_dev.php/search/query/" + extractLast(request.term), {
term: extractLast(request.term)
}, response);
},
search: function() {
// custom minLength
var term = extractLast(this.value);
if (term.length < 2) {
return false;
}
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function(event, ui) {
window.location = ("http://192.168.33.10/" + ui.item.link);
}
});
});
</script>
<div class="ui-widget">
<label for="search">Search</label>
<input type="text" id="search" />
</div>
你要去哪裏,從讓你的類別? – 2013-04-08 19:07:47
這些類別將來自搜索結果來自的JSON。 – user1406737 2013-04-08 19:10:02