2014-02-27 47 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() 
});