select2-隐藏搜索框 [英] select2 - hiding the search box
问题描述
对于我更重要的选择,Select2中的搜索框很棒.但是,在一个实例中,我仅选择了4个硬编码选项.在这种情况下,搜索框是多余的,看起来有点傻.有可能将其隐藏吗?我在网上浏览了文档,在构造函数中找不到任何选项.
For my more significant selects, the search box in Select2 is wonderful. However, in one instance, I have a simple select of 4 hard-coded choices. In this case, the search box is superfluous and looks a little silly being present. Is it possible to hide it somehow? I took a look through the documentation online and couldn't find any options for this in the constructor.
我当然可以只使用常规的html select,但是为了保持一致,我想尽可能使用Select2.
I could, of course, just use a regular html select, but for consistency I'd like to use Select2 if possible.
推荐答案
查看此线程 https://github.com/ivaynberg/select2/issues/489 ,您可以通过将minimumResultsForSearch设置为负值来隐藏搜索框.
See this thread https://github.com/ivaynberg/select2/issues/489, you can hide the search box by setting minimumResultsForSearch to a negative value.
$('select').select2({
minimumResultsForSearch: -1
});
这篇关于select2-隐藏搜索框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!