0

我升級到Bootstrap 3.0版,我發現typeahead模塊不存在。我正在使用Web服務,並使用以下方法調用我的函數並填充我的數據集。但是,使用twitter typeahead.js,我該如何調用我的函數,或者如何繼續使用舊的typeahead模塊?非常感謝您的幫助。謝謝。Bootstrap3 Typeahead - 調用'Remote'中的函數

  $("#searchVendor").typeahead({ 
      source: function (query) { 
        vieModel.callWebServiceFunctionList(counter1, query, isListCleared); 
     }); 

回答

0

Typeahead.js沒有直接使用函數的方法source。通過查詢值的標準方法是在remote屬性包含%QUERY URL字符串:

$("#searchVendor").typeahead({ 
      remote: '.../data.json?name=%QUERY' 
}); 

然而,這可能是不夠的,你的情況。 remote也可以是一個對象,具有應用於該URL的urlreplace函數。

因此,製作一個像callWebServiceFunctionList這樣的函數,它只是返回URL而不是實際調用Web服務。

$("#searchVendor").typeahead({ 
      remote: { 
       url: '.../data.json?counter=%COUNTER&query=%QUERY&isListCleared=%ISLISTCLEARED', 
       replace: function(url, query) { 
        return url.replace('%COUNTER', counter1).replace('%QUERY', query).replace('%ISLISTCLEARED', isListCleared); 
       } 
}); 

See the docsremote對象。

或者,您可以將JS僅用於Bootstrap 2.x的預先部分,並且您可能遇到格式問題it seems to work fine by itself(JSFiddle演示)的問題。