How to update the source Option in bootstrap-typeahead.js

前端 未结 3 576
执笔经年
执笔经年 2021-01-05 03:26

I am using bootstrap-typeahead in order to allow multiple selection. Here is the demo.

The original code has been update by @Sherbrow Twitter bootstrap typeahead

3条回答
  •  天涯浪人
    2021-01-05 04:06

    Based on the default updater method of typeahead :

    updater: function (item) {
      var pos = this.source.indexOf(item);
      if(pos != -1) {
        var newSource =
          this.source.slice(0,pos)
          .concat(this.source.slice(pos+1));
        this.source = newSource;
      }
      return item
    }
    

    Demo with multiple values (jsfiddle)

    Keep in mind that you can access this source from anywhere with $('sel').data('typeahead').source considering that the typeahead is initialized

提交回复
热议问题