我在它的最新版本中使用了select2js,但我不知道为什么,当我点击时,我的列表中默认有一个“s”。它使用Ajax调用,我把
minimumInputLength
为了避免这一点。这是我的电话:
$('.search-location').select2({
language: 'fr',
placeholder: "Ville ou CP",
minimumInputLength: 2,
maximumSelectionLength: 4,
width: '100%',
ajax: {
url: ajaxurl,
dataType: "json",
data: function (params) {
var queryParameters = {
q: params.term,
action: 'get_the_locations'
}
return queryParameters;
},
cache: false,
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.label,
id: item.number
}
})
};
}
}
}).on('select2:select', function (e) {
var data = e.params.data;
});
您可以在这里测试:
https://www.cabinet-hermes.fr/
在主搜索栏上,输入“ville,cp ou department”。谢谢。