【发布时间】:2017-06-06 10:54:24
【问题描述】:
我正在尝试通过引导标签输入设置标签,但它不起作用并给出以下错误:
TypeError: b.options.itemValue(...) is undefined
我的代码如下:
$('#searchGeoBottom').tagsinput({
maxTags: 5,
delay: 500,
itemValue: 'value',
itemText: 'text',
typeahead: {
displayKey: 'text',
source: function (query) {
if (ajax) {
ajax.abort();
}
var data = {term: query};
ajax = $.getJSON((baseUrl + "geoSearch"), data);
return ajax;
},
afterSelect: function () {
this.$element[0].value = '';
}
}
});
if (typeof searchGeo != 'undefined' && searchGeo != '') {
$('#searchGeoBottom').tagsinput('add', searchGeo);
}
我还尝试了以下在搜索时发现的方法:
var elt = $('#searchGeoBottom').tagsinput({....});
elt.tagsinput('add', searchGeo);
但它也不起作用,给出 elt 未定义或 elt 不是函数..
下面是我传入add函数的json:
[{"text":"Lahore. United States","value":4768156}]
【问题讨论】:
-
你能在你的问题中加入一个 jsfiddle 吗?
-
@AshiqurRahman 让我尝试在其中包含 jsfiddle,我也更新了我的问题,请检查它是否有助于您理解问题。谢谢!
-
你需要使用 toString();尝试使用 tagsinput('add',id:'someID', name:searchGeo.toString())
标签: javascript jquery html twitter-bootstrap tags