javascript - twitter-typeahead 不适用于 Bloodhound

标签 javascript jquery twitter twitter-typeahead

我正在尝试让 twitter typeahead 正常工作,但 type advance 功能不起作用。它不显示自动完成部分。 这是 JavaScript 代码。

 var films = new Bloodhound({
  datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.value); },
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  limit: 10,

  local: [{"id":1,"name":"English"},{"id":2,"name":"Hello"}]
  });

  films.initialize();

 $('.films .typeahead').typeahead(null, {
  name: 'film',
  displayKey: 'name',
  source: films.ttAdapter()
});

这是 html

 <div class="col-sm-6 films">
 <input class="typeahead form-control" name="films" type="text" autocomplete="off" value=""/>   

</div>

jsfiddle位置是http://jsfiddle.net/qLk8c/57/

不确定我错过了什么。

最佳答案

尝试将您的自定义 datumTokenizer 替换为:

Bloodhound.tokenizers.obj.whitespace('name')

这可能会达到您的预期。

编辑:

更新了jsfiddle:http://jsfiddle.net/qLk8c/58/

关于javascript - twitter-typeahead 不适用于 Bloodhound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25110795/

相关文章:

javascript - 从数据库中的ajax结果创建Javascript数组

scala - Spark Streaming 中的批处理大小

python - 无法使用 create_tweet() 发推文

php - update_with_media 使用 abraham 的 twitteroauth

javascript - ondomready和jquery的ready函数有什么区别?

javascript - 使用 Reduce 而不是链接 Filter 和 Map

jquery - IE jQuery 显示/隐藏 div 跳转问题

javascript - 如何在 Google Chrome 中为 SpeechSynthesisUtterance 设置默认语音?

javascript - AngularJS - Uncaught Error : [$injector:modulerr] Failed to instantiate module

jquery - 如何禁用特定输入字段的自动填充