我有一个Typeahead运行实例,从远程URL中提取JSON,这一切似乎都运行正常,除了UI实例似乎忽略了我的几个选项,即&#39 ;的minLength'并突出显示'。我使用的代码如下:
var airportsList = new Bloodhound({
name: 'airports',
limit: 20,
remote: {url: "http://full-url-here/search/%QUERY",
ajax: {type:'post',dataType:'jsonp',headers: {'cache-control': 'no-cache'}},
filter: function (parsedResponse) { return parsedResponse.locations; }
},
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace
});
// initialize the bloodhound suggestion engine
airportsList.initialize();
// instantiate the typeahead UI
$('.typeaheadField').typeahead(null, {
displayKey: 'name',
minLength: 3,
highlight: true,
source: airportsList.ttAdapter()
});
查看typeahead实例中的参数,它肯定会获取' displayKey'的值。和'来源'但由于某种原因,似乎忽略了那些中间的两个......?
答案 0 :(得分:3)
minLength
和highlight
是顶级配置而非每个数据集,请尝试以下操作:
$('.typeaheadField').typeahead({
minLength: 3,
highlight: true
},
{
displayKey: 'name',
source: airportsList.ttAdapter()
});