【发布时间】:2020-04-17 08:57:15
【问题描述】:
我在 rails 中有一个多选、select2 下拉菜单。目前,当我从 lis 中选择一些 2-3 个选项时,当我单击退格键时,所选元素将被删除,并且包含所有选项的下拉列表将被显示。但是当我输入一些首字母然后从列表中选择然后单击退格键时,下拉列表正在填充刚刚删除的选项。有没有办法在输入然后选择时,下拉列表将在单击退格键时显示完整列表? 我使用的代码是(根据https://github.com/select2/select2/issues/3354#issuecomment-132389291):
$.fn.select2.amd.require(['select2/selection/search'], function (Search) {
var oldRemoveChoice = Search.prototype.searchRemoveChoice;
Search.prototype.searchRemoveChoice = function () {
oldRemoveChoice.apply(this, arguments);
this.$search.val('');
};
$.fn.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
$('#reports_employee_id').select2({
matcher: oldMatcher(matchStart),
templateResult: formatSearch,
templateSelection: formatSelected,
maximumSelectionLength: 25,
placeholder: " "
})
});
});
提前致谢!!
【问题讨论】:
标签: javascript html ruby-on-rails jquery-select2