[英]Select2 Tags: Dynamicly add tag to input
我正在尋找一種將標簽添加到輸入標簽字段的解決方案。
我知道可以預先加載標簽,但是我找不到將標簽添加到輸入中的方法。 即使用特定功能,我可以追加選擇(帶有ID和TEXT)。
我已經搜索了很多,但是也許我陷入了死循環。 有什么建議么?
這是我初始化的方式:
$('.select2Input').select2({
tags: {
0: {
id: 'the id',
text: 'the text'
}
},
multiple: true,
minimumInputLength: 2
});
正如我在這個相關問題中提到的select2 destroy and recreate一樣 ,訣竅在於需要更改初始化選項時銷毀並重新創建 select2。 我懷疑這也是您需要做的事情。
基本語法是
$('#categoryid').select2("destroy");
createmycategoryidselect();
function createmycategoryidselect() {
// standard options
$opts = { ... }
// gather the current set of tag values and stick them in this new instance.
$opts.tags = { ... new tags ... }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.