有没有办法将一个项目附加到自动完成下拉列表的末尾,该下拉列表将包含 1-5 个项目?我使用过open
,但是因为我在加载时在下拉列表中附加了一个微调器,所以它不能很好地工作。
jQuery:
$("#search").autocomplete({
source: function(request, response) {
response([{loading: true}]);
return $.ajax({
url: "/search",
timeout: 10000,
dataType: "json",
data: {
query: request.term
},
success: function(data) {
var results;
results = [];
results = $.map(data, function(result) {
return {
label: result.name,
};
});
return response(results);
}
});
}
//open doesn't work because I have a spinning effect that opens a dropdown
//when the search is loading.
//open: function() {
// alert('test');
//}
})
.data( "autocomplete" )._renderItem = function( ul, item ) {
if(item.loading) {
return $( "<li id='spinner'></li>" )
.appendTo( ul );
}
};
谢谢!