Bootstrap tagsinput add tag with id and value

后端 未结 5 1304
轮回少年
轮回少年 2021-01-01 23:58

I am using Bootstrap Tags Input

I am trying to add tags dynamically.

$(\'.div-tag\').tagsinput(\'add\', \'vino\');

The above code

5条回答
  •  半阙折子戏
    2021-01-02 00:49

    There is nothing wrong with the library, but when you get this error it means there is a problem with the method initilization.

    Try to do it when the page is ready like so:

    $(document).ready(function(){
       $('#myInput').tagsinput({
           allowDuplicates: false,
           itemValue: 'id',
           itemText: 'label'
        });
    });
    
    $(".someButton").click(function(){
       $('#myInput').tagsinput('add', {id:1, label:"blah blah"});
    }
    

提交回复
热议问题