我已经将 Twitter Typeahead.js 集成到 Rails 应用程序中已有一段时间了,并且工作正常。
在一系列 gem 更新和一些依赖项移动到 Bower 之后,我现在在控制台中看到一个错误,并且 Typeahead.js 没有被正确调用。
Uncaught TypeError: Cannot read property 'whitespace' of undefined
上
queryTokenizer: Bloodhound.tokenizers.whitespace
这是什么意思,我该如何调试?
我的完整代码:
jQuery ->
if $('.country-typeahead').length
countries = new Bloodhound(
prefetch:
url: "../api/countries.json"
datumTokenizer: (datum) ->
Bloodhound.tokenizers.whitespace datum.name
queryTokenizer: Bloodhound.tokenizers.whitespace
)
countries.initialize()
$('.country-typeahead').typeahead null,
name: "countries"
displayKey: "name"
source: countries.ttAdapter()
json看起来像这样
[{"id":1,"name":"Aruba"},{"id":2,"name":"Afghanistan":""},{.....etc}]