Javascript 在引导标记输入中添加标记动态不起作用
我试图通过引导标记输入设置标记,但它不起作用,并出现以下错误:Javascript 在引导标记输入中添加标记动态不起作用,javascript,jquery,html,twitter-bootstrap,tags,Javascript,Jquery,Html,Twitter Bootstrap,Tags,我试图通过引导标记输入设置标记,但它不起作用,并出现以下错误: TypeError: b.options.itemValue(...) is undefined 我的代码如下: $('#searchGeoBottom').tagsinput({ maxTags: 5, delay: 500, itemValue: 'value', itemText: 'text', typeahead: { displayKey: 'text',
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}]
对于可能有相同问题的用户,请尝试以下代码:
var elt = $('#searchGeoBottom'); // get element
elt.tagsinput({....}); // initialize tagsinput
elt.tagsinput('add', searchGeo[0]); // adding one object at a time and not an array
你能在你的问题中加入一个JSFIDLE吗?@AshiqurRahman让我尝试加入JSFIDLE,我也更新了我的问题,请检查它是否有助于你理解这个问题。谢谢您需要使用toString();尝试使用tagsinput('add',id:'someID',name:searchGeo.toString())