我想显示自动填充结果, 显示结果的最大限制是多少?
代码示例:
function AutoCompletePositions(){
j$("#AddPosition").autocomplete({
source : allPositions
});
}
“#AddPosition”是从“allPositions”列表中获取值的字段。
答案 0 :(得分:1)
您可以使用css轻松隐藏元素:
<style>
.ui-widget li:nth-child(n+6) {
display: none;
}
</style>
这只会显示前5个选项
答案 1 :(得分:0)
显示的结果中没有定义的最大限制选项(请参阅documentation)。但是,您可以为源参数定义自定义函数,您可以在筛选列表上slice:
var allPositions = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"];
$("#AddPosition").autocomplete({
source: function(request, response) {
var results = $.ui.autocomplete.filter(allPositions, request.term);
response(results.slice(0, 10));
}
});
<强> JSFiddle 强>