typeahead.js返回“空白”数据集

时间:2019-02-05 19:27:48

标签: jquery autocomplete typeahead.js

我有一个问题,Twitter typeAhead返回空白结果,而官方文档也无济于事。

我期望什么?

<div class="tt-suggestion tt-selectable">Warcraft II: Tides of Darkness</div>
...

正在发生的事情:

在输入字段中键入内容时,typeAhead会返回空的html,就像这样,列表确实会根据获取的结果数量进行填充,因此它可以正常工作

<div class="tt-suggestion tt-selectable"></div>
<div class="tt-suggestion tt-selectable"></div>
<div class="tt-suggestion tt-selectable"></div>
<div class="tt-suggestion tt-selectable"></div>
<div class="tt-suggestion tt-selectable"></div>

我的代码:

var gameTitles= new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  remote: {
    url: '../api/autocomplete/%QUERY',
    wildcard: '%QUERY'
  }
});

$('#title').typeahead({minLength: 3}, {
  name: 'game-titles',
  display: 'value',
  source: gameTitles
});

作为参考,遥控器返回以下内容,因此我知道我的查询可以正确传递

[
  "Warcraft II: Tides of Darkness",
  "Warcraft II: Beyond the Dark Portal",
  "Warcraft III: Reign of Chaos",
  "Warcraft II: The Dark Saga",
  "Peggle: World of Warcraft Edition",
  "Warcraft III: Reforged Spoils of War Edition",
  "World of Warcraft",
  "Warcraft III: Reforged",
  "Warcraft: Orcs & Humans",
  "World of Warcraft: Legion"
]

1 个答案:

答案 0 :(得分:0)

Typeahead在数组中查找对象,默认情况下建议在这些对象中查找value,这可以通过将您希望使用的属性名称分配给{{1}来更改}属性

display

此外,不再维护typeAhead,selectize.js似乎是一个很好的选择

相关问题