是否可以设置自动完成的最大结果数?
我正在使用 jQuery UI
的 autocomplete
:优秀的插件!
我唯一不喜欢的是,如果我有一个包含 40 项
的列表,我只想显示 10 项
。
这是我的实际代码:
<script type="text/javascript">
$(function() {
var availableTags = [<%= m_strTags %>];
$("#myTags").autocomplete({
source: availableTags,
max: 20
});
});
</script>
是否可以输入一些参数来执行此操作?
I'm using autocomplete
of jQuery UI
: excellent plugin!
The only thing I don't like is that, if I have a list of 40 items
, I'd like to show only 10 items
.
This is my actual code :
<script type="text/javascript">
$(function() {
var availableTags = [<%= m_strTags %>];
$("#myTags").autocomplete({
source: availableTags,
max: 20
});
});
</script>
Is it possible put some parameters to do this thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
来自迁移指南:
http://www.learningjquery.com/2010/06/autocomplete-migration-guide
From the migration guide:
http://www.learningjquery.com/2010/06/autocomplete-migration-guide
如果您不想修改源列表,您可以尝试滚动结果:
http://jqueryui.com /演示/自动完成/#maxheight
If you do not want to modify the source list, you could try scrollable results:
http://jqueryui.com/demos/autocomplete/#maxheight
您可以尝试使用回调函数作为源来实现您自己的过滤器函数。类似于:
这基本上是尝试检查字符串数组中的每个元素,并执行不区分大小写的
contains
搜索。您可能需要修改它以仅检查startsWith
或endsWith
或您拥有的任何内容。当然,您可能还想使用 regex 来加快速度。我还在这里设置了一个简单的示例: http://jsfiddle.net/2exCC/
尝试搜索类似
C
的内容。这应该返回到scala
,并留下scheme
。You can try implementing your own filter function by using a callback function as a source. Something like:
This is basically trying to check each of the elements in your string array, and performing a case-insensitive
contains
search. You may want to modify it to check only forstartsWith
orendsWith
or whatever you have. Of course, you may also want to useregex
instead to speed things up a bit.I also setup a quick example here : http://jsfiddle.net/2exCC/
Try searching for something like
C
. This should return up toscala
, and leave behindscheme
.这是一个令人讨厌的解决方案,你确实应该寻找一个更好的解决方案,但如果你找不到任何东西,你可以在自动完成打开带有建议的弹出窗口时隐藏
.ui-menu-item
(open
事件)。This is a nasty solution, and you really should look for a nicer one, but if you won't find anything you can hide the
.ui-menu-item
's when autocomplete opens popup with suggestions (open
event).是的。您需要使用 setOptions() 函数。
示例:
http://docs.jquery.com/Plugins/Autocomplete/setOptions#options
Yes it is. You need to use the setOptions() function.
Example:
http://docs.jquery.com/Plugins/Autocomplete/setOptions#options