如何在bootstrap-typeahead.js中更新源选项 [英] How to update the source Option in bootstrap-typeahead.js
问题描述
我正在使用bootstrap-typeahead以允许多项选择。
这是演示。
I am using bootstrap-typeahead in order to allow multiple selection. Here is the demo.
原始代码已由@Sherbrow更新 Twitter bootstrap预先输入多个值
The original code has been update by @Sherbrow Twitter bootstrap typeahead multiple values
我的问题与以下用例有关:
插入 >阿拉斯加值,我想更新源不再显示
Alaska
值。
任何提示?
My question is related to the following use case:
after inserting Alaska
value, I would like to update the source not showing again Alaska
value.
Any hints?
推荐答案
我遇到了同样的问题,这个会给你节省很多时间。我用我的代码示例更新了您的旧 jsFiddle 。基本的是你需要做的事情
I had the same problem and this one will save you a lot of time. I've updated your old jsFiddle with my code example. The basic thing is that you need to do
var autocomplete = $('input').typeahead();
autocomplete.data('typeahead').source = newSource;
其中 newSource
是新数组。现在你只需要一个添加或删除元素的函数,或者你需要做的任何事情。
Where newSource
is the new array. Now you just need a function that adds or removes an element, or whatever you need to do with it.
这篇关于如何在bootstrap-typeahead.js中更新源选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!