我正在使用Typehead.js,它工作得很好,但我有一个特殊的情况,我不确定如何解决。
我使用的是hint:true,所以当用户开始输入时,搜索框就会用提示进行更新。如果用户在没有从列表中选择一个匹配项的情况下按enter键,我在输入字段中得不到任何值,并且我不知道从哪里获得提示的值。
这就是我初始化Typehead.js的方式
$('#search .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 2
},
{
name: 'tags',
displayKey: 'name',
source: substringMatcher()
});这就是我所说的提示。当用户编写ar时,他会得到architecture。

但是,正如您从HTML中看到的,我对输入没有任何值。
<input class="typeahead tt-hint" type="text" readonly="" autocomplete="off" spellcheck="false" tabindex="-1">
<input class="typeahead tt-input" type="text" placeholder="Search" autocomplete="off" spellcheck="false" dir="auto">发布于 2016-08-10 23:26:45
您可以从Javascript代码而不是html代码中添加这些值。
你需要做这样的事情
var key_attributes = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('key'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
});
key_attributes.initialize();
$('.attr-row').last().find('.taginput-key').typeahead({
hint: true,
highlight: true,
minLength: 0
}, {
name: 'key',
display: 'key',
source: key_attributes.ttAdapter()
});https://stackoverflow.com/questions/29505321
复制相似问题