2014-02-27 49 views
0

我有一个Typeahead运行的实例,从远程URL拉入JSON,并且它似乎一切正常,除了UI实例似乎忽略了几个我的选项,即'minLength'和'highlight'。我正在使用的代码如下:Typeahead UI忽略选项(v0.10)

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() 
}); 

在预输入情况下,在我的参数来看,这绝对是“displayKey”和“源”捡值,但似乎忽略那些中间的两个对一些原因...?

回答

3

minLengthhighlight是顶级CONFIGS,而不是每个数据集,那么试试这个:

$('.typeaheadField').typeahead({ 
    minLength: 3, 
    highlight: true 
}, 
{ 
    displayKey: 'name', 
    source: airportsList.ttAdapter() 
});