【问题标题】:Select2 4.0.1: How to return only first character matched results?Select2 4.0.1:如何只返回第一个字符匹配的结果?
【发布时间】:2015-12-05 15:44:45
【问题描述】:

我使用的是 Select2 版本 4.0.1,在搜索任何名称时,我只想显示那些与第一个字符匹配的记录。例如:我从“c”开始,然后只显示那些以“c”开头的名字。见附件。

我在 stackoverflow 上尝试了不同的方法,但没有运气。 例如:也试过这个,但得到这个错误“select2 text.toUpperCase is not a function

$("select").select2({
    matcher: function(term, text) {
      return text.toUpperCase().indexOf(term.toUpperCase())==0;
    }
});

【问题讨论】:

标签: jquery jquery-select2 jquery-select2-4


【解决方案1】:

您使用完整版的 select2 吗? 如果是的话,试试这个例子

function matchStart (term, text) {
  if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
    return true;
  }

  return false;
}

$.fn.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
  $("select").select2({
    matcher: oldMatcher(matchStart)
  })
});

【讨论】:

  • 不,我使用的是普通版本。我会试试你的。我希望你的代码能解决这个问题。我会相应地更新你
猜你喜欢
  • 1970-01-01
  • 2014-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-17
  • 2016-05-23
  • 1970-01-01
相关资源
最近更新 更多