tagsinput仅显示未找到

时间:2017-10-21 12:43:34

标签: typeahead.js bootstrap-tags-input

它最初起作用,但它提供了表格中的所有数据。我试图改变一些东西只建议相关的名字但是当我把它归还给我的原始代码时它停止了工作。

$(function(){

         // constructs the suggestion engine
        var shoppableBrands = new Bloodhound({
            datumTokenizer: Bloodhound.tokenizers.whitespace('name'),
            queryTokenizer: Bloodhound.tokenizers.whitespace,
             remote: {
                // url: 'tagToText.data('api')+'/%QUERY%','
        url: '//staging.sap.com/shoppable_brands/api',

                wildcard: '%QUERY',
                rateLimitBy: 'debounce',
                rateLimitWait: 300,
            }
        });
                shoppableBrands.initialize();

                $('#bloodhound .typeahead').tagsinput({
                    //maxTags:tagLimit,
                  //tagClass: 'label label-info '+singleTag,
                    confirmKeys: [13, 188],
                    itemValue: 'id',
                    itemText: 'name',
                    typeaheadjs: {
                        limit: 50,
                        hint:false,
                        source: shoppableBrands.ttAdapter(),
                        templates: {
                            suggestion: function(data){
                                var name = data.name;
                                return '<div class="tt-suggestion tt-selectable" title="'+name+'" >\
                                '+name+'</div>';
                            },


                         notFound : function(){
                                return '<div class="tt-suggestion" title="Not Found" >No Results Found</div>';
                            }
                        }
                    }
                });

                $('input#shoppable_brand_name').on('itemAdded', function(event) {
                    var type = event.item;
                    $('#shoppable_brand_type').val(type.type);
                    console.log(type.type);
                });



                $('#bloodhound .typeahead').on('beforeItemAdd', 

function(event) {
                       if($(this).data('limit') == 1) $(this).tagsinput('removeAll');
                    });

});

0 个答案:

没有答案