2015-04-28 43 views
3

我已經設置了typeahead.js版本0.11.1以從geobytes API中提取城市。這裏,不只是一個codepen:來自typeahead.js的奇怪行爲

http://codepen.io/jeremeevans/pen/OVPram

var cities = new Bloodhound({ 
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace(), 
    queryTokenizer: Bloodhound.tokenizers.whitespace, 
    remote: { 
     url: "http://gd.geobytes.com/AutoCompleteCity?callback=?&template=<geobytes%20city>,%20<geobytes%20code>&filter=US&q=%QUERY", 
     wildcard: "%QUERY", 
     dataType: "jsonp", 
     transform: function (response) { 
      return response; 
     } 
    }, 
    limit: 10 
}); 

$("#city").typeahead({ 
    minLength: 3, 
    highlight: true, 
    hint: true 
}, { 
    name: "US-Cities", 
    source: cities 
}); 

的怪異行爲,我看到的是,當我開始打字西雅圖,當我到達「座位」這只是列出兩個結果,「 Seaton,IL「和」Seatonville,IL「。我知道API會返回更多的結果,其中包括「華盛頓州西雅圖」。此外,如果您開始搜索「Everett」,所有搜索結果將在「Everet」中刪除,並且在您到達「Everett」之前保持隱形狀態 - 此時會顯示「Everett,MA」和「Everett,PA」,但不包含「Everett ,WA「。

與0.11.1版相關的選項和文檔的文檔在https://github.com/twitter/typeahead.js上相當糟糕 - 我真的很感謝有關如何使用它的一些見解,而不是它的屠夫,它會顯示結果。

+0

也許檢查出:http://stackoverflow.com/questions/31007825/bootstrap-typeahead-not-showing-hints-as-expected – Reid

回答

1

我遇到了一些物品丟失的情況。 我所做的是將typeahead選項的限制設置爲10. 它適用於我。

+0

我有一個類似的問題,並限制到10後,它工作正常,但它是如此奇怪:S – Silence

+0

你可以找到這個錯誤的原因[這裏](https://github.com/twitter/typeahead.js/issues/1415),並有更好的解決方案 – Keyleo