我直接使用时,后台一直报Uncaught Can't add objects when itemValue option is not set错误,
代码如下:
<div> <input id="uploadFiles" placeholder="请选择..." data-role="tagsinput" /> </div>
$("#uploadFiles").tagsinput({ itemValue: 'id', itemText: 'text', }); var test={id:'adfa',text:'fff'}; $("#uploadFiles").tagsinput('add', test);
查了半天,没找到问题所在,后来在stackoverflow发现一个相同的错误的帖子:
http://stackoverflow.com/questions/31926025/bootstrap-tagsinput-cant-add-objects-when-itemvalue-option-is-not-set
给了我启发,原来是写了data-role="tagsinput"属性,去掉后就OK啦