2013-02-13 52 views
-1

我在的地方下面的代碼使用版本2.3.0初始化預輸入:Twitter的引導不事先鍵入的內容不加載AJAX數據

jQuery('#search_terms').typeahead({ 
    source: function(query, process) { 
     return jQuery.ajax({ 
      url: '/api/path', 
      type: 'GET', 
      data: {q: query}, 
      dataType: 'json', 
      success: function (json) { 
       return process(json.suggestion); 
      } 
     }); 
    } 
}); 

我驗證過預輸入作品代靜態數據。我已經看到,json.suggestion按照預期評估一個單詞。 ajax響應本身如下所示:

{"suggestion":"word"} 

但是,Bootstrap拒絕將響應加載到預先輸入。我錯過了什麼?我承認我無法通過ajax找到Bootstrap Typeahead的詳細文檔,而不是在這裏。

在此先感謝。

回答

5

我們發現Bootstrap Typeahead利用自己的匹配過濾器對我們的ajax數據進行了二次猜測。通過強制匹配成爲真實,我們解決了這個問題:

jQuery('#search_terms').typeahead({ 
    source: function(query, process) { 
     jQuery.ajax({ 
      url: 'api/path', 
      type: 'GET', 
      data: {q: query}, 
      dataType: 'json', 
      success: function (json) { 
       process([json.suggestion]); 
      } 
     }); 
    }, 
    matcher: function (param) {return true} 
}); 
相關問題