Twitter bootstrap 引导-使用标记输入自动完成

Twitter bootstrap 引导-使用标记输入自动完成,twitter-bootstrap,Twitter Bootstrap,嗨,我想使用自动完成功能和标记输入 带引导 我也有一个外部json文件。 我已经添加了外部json,以及它的外观。。 有人能帮我吗 谢谢 参考链接 代码 $('input').tagsinput({ 提前打印:{ 来源:函数(打印头、查询) { $.ajax({ url:“http://localhost:56558/keywords/test.html", 数据类型:“json”, 成功:功能(数据){ var return_list=[],i=data.length; 而(我--){ re

嗨,我想使用自动完成功能和标记输入 带引导 我也有一个外部json文件。 我已经添加了外部json,以及它的外观。。 有人能帮我吗 谢谢 参考链接

代码


$('input').tagsinput({
提前打印:{
来源:函数(打印头、查询)
{
$.ajax({
url:“http://localhost:56558/keywords/test.html",
数据类型:“json”,
成功:功能(数据){
var return_list=[],i=data.length;
而(我--){
return_list[i]={Name:data[i].value,value:data[i].id};
}
进程(返回列表);
}
});
}
}
});
[{“id”:“Netta rufina”,“label”:“Red crest Pochard”,“value”:“Red crest Pochard”},{“id”:“Sterna sandvicensis”,“label”:“Sandwich Tern”,“value”:“Sandwich Tern”,“value”:“Saxicola rubetra”,“label”:“Whinchat”,“value”:“Whinchat”},{“id”:“Saxicola rubicola”,“label”:“European Stonechat”,“value”:“European Stonechat”},{“id”“拉尼乌斯参议员”,“标签”:“伍德查特伯劳鸟”,“价值”:“伍德查特伯劳鸟”},{“id”:“Coccothraustes Coccothraustes”,“标签”:“Hawfinch”,“价值”:“Hawfinch”},{“id”:“Ficedula hypoleuca”,“标签”:“欧亚斑蝶”、“价值”:“欧亚斑蝶”},{“id”:“Sitta europaea”,“标签”:“欧亚斑蝶”、“价值”:“欧亚牛头雀”},{“id”:“Pyrrhula-Pyrrhula”,“标签”:“欧亚牛头雀”,“价值”:“欧亚牛头雀”},{“id”:“条纹家蝇”,“标签”:“斑点捕蝇器”,“价值”:“斑点捕蝇器”},{“id”:“卡杜利斯氯”,“标签”:“欧洲绿翅鸟”,“价值”:“欧洲绿翅鸟”},{“id”:“卡杜利斯卡杜利斯”,“标签”:欧洲金翅雀,“价值”:“欧洲金翅雀”}]

不确定这是否有帮助,但有一个类似的问题,这就是我为自己编写的代码

    <input id="my-tags" type="text" placeholder="Add tags" />
    <script type="text/javascript">
        var colors = ["red", "blue", "green", "yellow", "brown", "black"];
        var elt = $('#my-tags');

        elt.tagsinput('input').typeahead({
            local: colors,
            prefetch: '/assets/data/countries.json'
        }).bind('typeahead:selected', $.proxy(function (obj, datum) {
            this.tagsinput('add', datum.value);
            this.tagsinput('input').typeahead('setQuery', '');
        }, elt));
    </script>

提前道歉-这应该被理解为一个评论,而不是一个回答(我的排名不够高,无法发表评论)

Corey的答案非常适合typeahead 0.9版,其中存在“setQuery”方法。 话虽如此,typeahead 1.0中存在一个问题:“setQuery”已不存在。它的功能似乎已被“val”取代。我正试图让它工作,但似乎存在一个问题,即在选择标记时类“tt hint”未被清除,导致输入字段混乱。是否有其他人遇到此问题?

新链接:
    <input id="my-tags" type="text" placeholder="Add tags" />
    <script type="text/javascript">
        var colors = ["red", "blue", "green", "yellow", "brown", "black"];
        var elt = $('#my-tags');

        elt.tagsinput('input').typeahead({
            local: colors,
            prefetch: '/assets/data/countries.json'
        }).bind('typeahead:selected', $.proxy(function (obj, datum) {
            this.tagsinput('add', datum.value);
            this.tagsinput('input').typeahead('setQuery', '');
        }, elt));
    </script>
 /*------ typeahead ------*/

.twitter-typeahead .tt-query,
.twitter-typeahead .tt-hint {
       margin-bottom: 0;
}
.tt-suggestion.tt-is-under-cursor {
    color: #fff;
    background-color: #0081c2;
    background-image: -moz-linear-gradient(top, #9FDD48, #8CC43E);
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#9FDD48), to(#8CC43E));
    background-image: -webkit-linear-gradient(top, #9FDD48, #8CC43E);
    background-image: -o-linear-gradient(top, #9FDD48, #8CC43E);
    background-image: linear-gradient(to bottom, #9FDD48, #8CC43E);
    background-repeat: repeat-x;
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff9FDD48', endColorstr='#ff8CC43E', GradientType=0)
}
.twitter-typeahead .tt-hint {
    /*display: none;*/ your choice here...
}
.twitter-typeahead .hint-small {
    height: 30px;
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 3px;
    line-height: 1.5;
}
.twitter-typeahead .hint-large {
    height: 45px;
    padding: 10px 16px;
    font-size: 18px;
    border-radius: 6px;
    line-height: 1.33;
}
.tt-dropdown-menu {
    min-width: 160px;
    margin-top: 2px;
    padding: 5px 0;
    background-color: #fff;
    border: 1px solid #ccc;
    border: 1px solid rgba(0,0,0,.2);
    *border-right-width: 2px;
    *border-bottom-width: 2px;
    -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
    border-radius: 6px;
    -webkit-box-shadow: 0 5px 10px rgba(0,0,0,.2);
    -moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
    box-shadow: 0 5px 10px rgba(0,0,0,.2);
    -webkit-background-clip: padding-box;
    -moz-background-clip: padding;
    background-clip: padding-box;
}
.tt-suggestion {
    display: block;
    padding: 3px 20px;
}
.tt-suggestion.tt-is-under-cursor {
    color: #fff;
    background-color: #0081c2;
    background-image: -moz-linear-gradient(top, #9FDD48, #8CC43E);
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#9FDD48), to(#8CC43E));
    background-image: -webkit-linear-gradient(top, #9FDD48, #8CC43E);
    background-image: -o-linear-gradient(top, #9FDD48, #8CC43E);
    background-image: linear-gradient(to bottom, #9FDD48, #8CC43E);
    background-repeat: repeat-x;
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff9FDD48', endColorstr='#ff8CC43E', GradientType=0)
}
.tt-suggestion.tt-is-under-cursor a {
    color: #fff;
}
.tt-suggestion p {
     margin: 0;
}