Javascript 使用ajax时,在onSelect事件中选择2(4.00)返回undefined
我正在使用Select2(ver4.00)并使用ajax方法加载远程数据 我需要检索所选选项的标题,但在select2中:select事件数据未定义 我的代码:Javascript 使用ajax时,在onSelect事件中选择2(4.00)返回undefined,javascript,jquery,ajax,jquery-select2,jquery-select2-4,Javascript,Jquery,Ajax,Jquery Select2,Jquery Select2 4,我正在使用Select2(ver4.00)并使用ajax方法加载远程数据 我需要检索所选选项的标题,但在select2中:select事件数据未定义 我的代码: $(".js-data-action-terms").select2({ ajax: { url: ajaxurl + "?action=terms", dataType: 'json', data: function (params) { return
$(".js-data-action-terms").select2({
ajax: {
url: ajaxurl + "?action=terms",
dataType: 'json',
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, page) {
return {
results: data.items
};
},
cache: false
},
escapeMarkup: function (markup) {
return markup;
},
minimumInputLength: 1,
templateResult: formatRepo,
templateSelection: formatRepoSelection
});
$('.js-data-action-terms').on("select2:select", function(e) {
console.log(e);
});
结果日志:
在Select2 4.0.0中,所选对象从
evt.data
属性移动到evt.params.data
。现在,Select2中事件的所有额外数据都放在evt.params
中以保持一致性。谢谢!这就是我要找的!