我正在使用Select 2 v4,并且添加了标签:true,以便用户搜索和选择新选项。我想要的是能够在用户选择其新选项而不是现有选项时触发特定事件。那我该怎么办呢?
$("#smart_search").select2({
placeholder: "Start typing what you need...",
data: data,
width: '300px',
formatSelection: function(item) {return item.id},
formatResult: function(item) {return item.name},
tags: true
}).on('change', function (e) {
smart_search = $(this).val();
console.log('and the value is: ' + smart_search);
});
谢谢!