2017-06-06 44 views
-1

我正在嘗試設置通過引導標籤輸入標籤,但它不工作添加標籤,並給予下列錯誤:在引導標籤輸入動態工作不

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不是一個函數..

以下是JSON我傳遞在增加功能:

[{"text":"Lahore. United States","value":4768156}] 
+0

你能包括你的問題jsfiddle嗎? –

+0

@AshiqurRahman讓我嘗試包含jsfiddle,我也更新了我的問題,請檢查它是否有助於您理解問題。謝謝! –

回答

0

對於那些誰可能有同樣的問題,試試這個代碼:

var elt = $('#searchGeoBottom'); // get element 
elt.tagsinput({....}); // initialize tagsinput 
elt.tagsinput('add', searchGeo[0]); // adding one object at a time and not an array