我正在使用Bootstrap Tags Input
我正在尝试动态添加标签。
$('.div-tag').tagsinput('add', 'vino');
上面的代码工作正常,但是当我尝试以下代码时:
$('.div-tag').tagsinput('add', { id: 1, text: 'some tag' });
我收到错误:
Uncaught 未设置 itemValue 选项时无法添加对象
请帮我添加带有 ID 和值的标签。
最佳答案
初始化标签输入,如
$('.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' });
就这样;
关于jquery - Bootstrap taginput 添加带有 id 和 value 的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29703773/