【发布时间】:2019-10-23 09:43:07
【问题描述】:
WooCommerce 在州和国家/地区的送货和帐单地址字段中使用 select2。我想这样当你搜索 ka 时,最上面的结果是 Kansas 而不是 Alaska。
我查看了 select2 的文档,发现:
https://select2.org/searching#customizing-how-results-are-matched
但该解决方案适用于有孩子的情况。我不知道如何编辑记录的示例以使其与 WooCommerce 一起使用。另一篇 SO 文章建议这样做:
function matchCustom(term, text) {
console.log('matcher is running');
if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
return true;
}
}
jQuery( document ).ready(function() {
$(".state_select").select2({
matcher: matchCustom
});
});
使用上面的代码,当我搜索ka 时,顶部结果是Alaska 而不是Kansas。
我查看了以下 SO 问题:
jquery select2 plugin how to match only beginning of word
jquery select2 plugin how to get only the result 'myString%'
select2 search - match only words that start with search term
【问题讨论】:
标签: woocommerce jquery-select2 dropdown matcher