我正在尝试将下面的代码与 typeahead.js v 0.10 一起使用
// instantiate the bloodhound suggestion engine
var numbers = new Bloodhound({
datumTokenizer: function(d) { return d; },
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: ["(A)labama","Alaska","Arizona","Arkansas"]
});
// initialize the bloodhound suggestion engine
numbers.initialize();
console.log(numbers.get('a'));
事实上,我试图解决这个问题:https ://github.com/bassjobsen/Bootstrap-3-Typeahead/issues/26 我希望如下所示的事情应该是可能的:
$('.typeahead').typeahead(
{
items: 4,
source:function(query){return numbers.get(query)}
});
更新
的例子。用于ttAdapter()
设置预先输入的来源。此函数还可用于设置Bootstrap-3-Typeaheadsource
的属性(接受字符串数组或函数):
// instantiate the bloodhound suggestion engine
var numbers = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,//function(d) { return d; },
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: ["(A)labama","Alaska","Arizona","Arkansas","Arkansas2","Barkansas"]
});
// initialize the bloodhound suggestion engine
numbers.initialize();
$('.typeahead').typeahead(
{
items: 4,
source:numbers.ttAdapter()
});
Bloodhound.js 显示:
ttAdapter: function ttAdapter() {
return _.bind(this.get, this);
}
因此ttAdapter()
返回一个函数 (get()),该函数可以由具有查询作为参数的源设置。