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

问题描述 投票:2回答:1

我有一点与Twitter的typeAhead返回空白结果的问题,官方文档的都没有任何帮助。

我是什么期待:

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

怎么了:

当在输入字段中键入,预输入返回空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"
]
jquery autocomplete typeahead.js
1个回答
0
投票

预输入查找在数组中,默认情况下您的建议是对象寻找在这些对象value,这可以通过指定您希望属性的名称更改为被用来将display财产

$('#title').typeahead({}, {
  name: 'game-titles',
  display: 'WHATEVER PROPERTY YOU WISH DISPLAYED',
  source: gameTitles
});

此外,不再被保持预输入,selectize.js似乎是一个很好的选择

© www.soinside.com 2019 - 2024. All rights reserved.