Select 2:如何创建列表中已存在的选项
Select 2: How to create an option which already exists in the list
我有一个 select 和 tags:true, multiple
,从数据库中填充。现在只有当列表中不存在新选项时才能创建新选项。创建的选项在列表的第一个 new option while not exists But I can't create option with the same text which is shown here
我怎样才能做到这一点?
已更新:link 标记文档 https://select2.org/tagging
您需要设置值,然后它起作用:
var lastId = $(".selectExample option").length + 1
var newState = new Option('Orange', lastId, true, true);
$(".selectExample").append(newState).trigger('change');
查看 playground 中的完整示例:https://jsfiddle.net/denisstukalov/phnk05od/9/#&togetherjs=sfjozzpr9N
我有一个 select 和 tags:true, multiple
,从数据库中填充。现在只有当列表中不存在新选项时才能创建新选项。创建的选项在列表的第一个 new option while not exists But I can't create option with the same text which is shown here
我怎样才能做到这一点?
已更新:link 标记文档 https://select2.org/tagging
您需要设置值,然后它起作用:
var lastId = $(".selectExample option").length + 1
var newState = new Option('Orange', lastId, true, true);
$(".selectExample").append(newState).trigger('change');
查看 playground 中的完整示例:https://jsfiddle.net/denisstukalov/phnk05od/9/#&togetherjs=sfjozzpr9N