我直接使用時,后台一直報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啦
