更改选择的 jquery 插件中的搜索行为
我正在使用 jQuery 的 Chosen 插件,并且希望搜索行为稍微改变一下(单选)。搜索仅会匹配搜索字符串中单词开头的匹配结果。我想将其扩展到斜杠和括号之后的单词。
例如: 搜索字符串:“第二”与项目“第一/第二”或“第一(第二)”不匹配。
我怀疑只需向构造函数添加选项就可以改变这一点,但我愿意更改/硬编码源脚本。
I'm using the Chosen plugin for jQuery and would like the search behavior to change a bit (single select). Searching only results in hits where the beginning of a word in the seach string matches. I would like to extend this to also hit words after slash and brackets.
For example:
search string: "second" does not match items "first/second" or "first (second)".
I doubt this is changeble by simply adding options to constructor, but I am willing to change/hardcode source script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
正如最近的一些答案中提到的,该插件现在实现了一个更改搜索行为的选项:
选项文档< /a>
该插件不提供更改搜索方法行为的选项。
如果您愿意更改插件源本身,可以使用以下方法。
在插件中进行搜索的方法是
Chosen.prototype.winnow_results
。它使用正则表达式来匹配“以”搜索词“开头”的文本:将其更改为:
DEMO< /a>
As mentionned in some more recent answers, the plugin now implemements an option to change the search behavior:
Options documentation
The plugin does not provide an option to change the search method behavior.
If you're willing to change the plugin source itself, here's a way to do it.
The method that makes the search in the plugin is
Chosen.prototype.winnow_results
. It uses a regular expression that matches text that "starts with" the search term:Change it to:
DEMO
搜索行为可以使用选项
search_contains
设置,默认情况下
false
将其设置为
true
,选择的也会在内部查找匹配项,而不是仅仅是开始:The search behavior can be set with the option
search_contains
This is by default
false
Set it to
true
, and chosen will also find matches inside instead of only the beginning:与 Chosen 1.0 一样,只需添加选项 {search_contains: true}
就可以玩得开心。
As in Chosen 1.0, just add option {search_contains: true}
Have fun.
在选择的1.0中我在第301和302行做了
in chosen 1.0 i did on line 301&302
有选项
search_contains
可用于搜索选项中的子字符串,可用作:There is option
search_contains
available to search sub-string in options and can be used as: