使用select2显示匹配optgroup的结果 [英] Display result matching optgroup using select2

查看:313
本文介绍了使用select2显示匹配optgroup的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Bootstrap 3中使用 select2 . 现在,我想知道如果搜索与optgroup名称匹配,同时仍然能够搜索项目,是否可以显示所有optgroup项目.如果可能的话,我该怎么办?

I'm using select2 with Bootstrap 3. Now I would like to know whether it is possible to display all optgroup items if the search matches the optgroup name while still being able to search for items as well. If this is possible, how can I do it?

推荐答案

实际上是通过修改匹配器opt找到的解决方案

Actually found the solution by modifying the matcher opt

 $("#myselect").select2({
    matcher: function(term, text, opt){
         return text.toUpperCase().indexOf(term.toUpperCase())>=0 || opt.parent("optgroup").attr("label").toUpperCase().indexOf(term.toUpperCase())>=0
    }
});

在每个optgroup中都设置了label属性的前提下.

Under the premise that the label attribute has been set in each optgroup.

这篇关于使用select2显示匹配optgroup的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆