Bootstrap标签输入带有ID和值的添加标签 [英] Bootstrap tagsinput add tag with id and value
本文介绍了Bootstrap标签输入带有ID和值的添加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用引导标签输入
我正在尝试动态添加标签.
I am trying to add tags dynamically.
$('.div-tag').tagsinput('add', 'vino');
上面的代码工作正常,但是当我尝试以下代码时:
The above code works fine, but when I try the following code:
$('.div-tag').tagsinput('add', { id: 1, text: 'some tag' });
我得到了错误:
Uncaught Can't add objects when itemValue option is not set
请帮助我添加具有ID和值的标签.
Please help me to add tag with id and value.
推荐答案
初始化标签输入,例如
$('.div-tag').tagsinput({
allowDuplicates: false,
itemValue: 'id', // this will be used to set id of tag
itemText: 'label' // this will be used to set text of tag
});
添加动态标签
$('.div-tag').tagsinput('add', { id: 'tag id', label: 'tag lable' });
就这样;
这篇关于Bootstrap标签输入带有ID和值的添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文