1

我已经将 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}]
4

2 回答 2

0

包括 typeahead.bunde.js 而不是 typeahead.js 问题是因为缺少依赖项 .bundle 包含所有必需的依赖项

于 2015-04-12T14:06:51.730 回答
0

您可能已经想通了,但是由于我遇到了同样的问题,我想我会发布我的解决方案。

不要在 Bower 中使用 Bloodhound 包并删除对该库的任何引用。您只需要 typeahead.js,因为它包含 Bloodhound。

于 2015-03-19T20:25:37.620 回答