如果我理解正确,在v4.0.0之前正确使用matcher是:
$('#myselect').select2({
...
matcher: function(term, text) {
// return true if matches, false if not
}
})
Run Code Online (Sandbox Code Playgroud)
使用4.0.2这不起作用--AFAICT只有一个参数matcher,它是一个对象.我可以使用相同的函数签名并将其打包oldWrapper,但我想避免这种情况......我无法找到任何示例或文档.那么,我如何使用新的匹配器?或者至少,功能签名是什么?
找到它:https://github.com/select2/select2/blob/master/src/js/select2/defaults.js(搜索function matcher).
基本上,函数签名是:
matcher: function (params, data) {
// should return:
// - null if no matches were found
// - `data` if data.text matches params.term
}
Run Code Online (Sandbox Code Playgroud)
然而,我的问题与"文本"是一个硬编码的字段名称有关 - 我当然正在使用其他东西.希望它可以帮助某人.