Man*_*kla 13 jquery bootstrap-tags-input
我正在使用Bootstrap Tags Input
我正在尝试动态添加标签.
$('.div-tag').tagsinput('add', 'vino');
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,但是当我尝试以下代码时:
$('.div-tag').tagsinput('add', { id: 1, text: 'some tag' });
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Uncaught Can't add objects when itemValue option is not set
请帮我添加id和值的标签.
Man*_*kla 17
初始化标签输入,如
$('.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
});
Run Code Online (Sandbox Code Playgroud)
添加动态标记
$('.div-tag').tagsinput('add', { id: 'tag id', label: 'tag lable' });
Run Code Online (Sandbox Code Playgroud)
而已;
小智 12
我花了几个小时才发现,只有在你的数据中删除了data-role ="tagsinput"时才能正常工作
<input class="div-tag" />
Run Code Online (Sandbox Code Playgroud)