【问题标题】:Why is typeahead.js/ bloodhound returning "Cannot read property 'whitespace' of undefined"为什么 typeahead.js/bloodhound 返回“无法读取未定义的属性‘空白’”
【发布时间】:2015-02-03 08:43:46
【问题描述】:

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

【问题讨论】:

    标签: ruby-on-rails typeahead.js bloodhound


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-11-19
        • 1970-01-01
        • 2020-07-01
        • 2020-11-10
        • 2019-09-01
        • 2019-01-15
        • 1970-01-01
        相关资源
        最近更新 更多