繁体   English   中英

“[object Object]”显示在带有 bootstrap3-typeahead 和 tagsinput 的输入字段中

[英]“[object Object]” showing in input field with bootstrap3-typeahead and tagsinput

当一个标签被选中时,标签被正确添加,但文本[object Object]被附加到输入框中。 (见下图)

我正在使用 Bootstrap 3、JQuery、Bootstrap3-typeahead 和 bootstrap-tagsinput(所有最新版本)

该表单位于模态窗口中。

标签错误

这是代码:

jQuery('#banner_geo_locations').tagsinput({
    itemValue: 'value',
    itemText: 'text',
    typeahead: {
        displayKey: 'text',
        source: function (query) {
            return jQuery.get("http://dev.marijuanaweeklycoupons.com/?action=ajax|cityStateSsearchTags&PageSpeed=off&q=" + query);
        }
    }
});

阿贾克斯看起来像:

[{"value":"2908762","text":"Dixon Corner, AL"},
{"value":"2956030","text":"Dixon Corner, ME"},
{"value":"3008251","text":"Dixon Corner, PA"},
{"value":"2931983","text":"Dixon Crossroads, GA"},
{"value":"3017149","text":"Dixon Crossroads, SC"},
{"value":"2959449","text":"Dixon Estates, MD"},
{"value":"2959450","text":"Dixon Hill, MD"},
{"value":"2993971","text":"Dixon Landing, NC"},
{"value":"2908763","text":"Dixon Shop, AL"},
{"value":"2938722","text":"Dixon Springs, IL"}]

小提琴中看到它

这是图书馆的问题。

添加以下内容可以解决问题:

afterSelect: function(val) { this.$element.val(""); },

像这样,

jQuery('#banner_geo_locations').tagsinput({
    itemValue: 'value',
    itemText: 'text',
    typeahead: {
        displayKey: 'text',
        afterSelect: function(val) { this.$element.val(""); },
        source: function (query) {
            return jQuery.get(current_web_root + "?action=ajax|cityStateSearchTags&PageSpeed=off&q=" + query);
        }
    }
});

见 jsfiddle

https://jsfiddle.net/rgaxuyda/11/

幸运的爱德华,它有效,谢谢。

<script>
    var elt = $('#inputSoftwareList');
    elt.tagsinput({
        itemValue: 'value',
        itemText: 'text',
        typeahead: {
            source: function(query) {
                return $.getJSON('cities.json');
            },
            afterSelect: function(val) { this.$element.val(""); }
        }
    });

</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM