将管道设置为Select2的定界符 [英] Set pipe as the delimiter for Select2
问题描述
我有一个多选下拉菜单,我想将管道(|
)设置为定界符.
I have one multiple select dropdown, and I want to set pipe (|
) as the delimiter.
例如,当用户选择多个选项(例如Option1,Option2和Option3)时,则应分开(定界)如下所示的值:
For example, when a user selects multiple options (like Option1, Option2 and Option3) then it should separate (delimit) the values like this:
Option1 | Option2 | Option3
Option1|Option2|Option3
下面是我的代码:
$("#granttype").select2({ allowClear: true, tags: true, tokenSeparators: ['|'] });
我是在$document.ready()
函数中编写的.
推荐答案
如果您的问题仍未解决,这就是答案!在旧版本的select2上,您必须使用'separator'而不是'tokenSeparators,像这样.
incase your problem is not resolved yet, here is the answer! On older versions of select2 you got to use 'separator' instead of 'tokenSeparators, like this.
jQuery('selector').select2({
separator: ";",
allowClear:true,
...
...
});
尽管不确定您是否可以选择select2的版本,但最好还是保留两个选项,就像这样.
Although as a fall back if you're not sure about the version of select2, the preferred way is to keep both the options, like this.
jQuery('selector').select2({
tokenSeparators: [';'],
separator: ";",
allowClear:true,
...
...
});
这篇关于将管道设置为Select2的定界符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!