我使用twitter的typeahead 0.10與遠程URL從服務器檢索JSON結果。Typeahead 0.10防止緩存
我想阻止客戶端緩存,以便始終在 服務器上進行搜索。我怎樣才能做到這一點?
請參閱下面我的代碼:
// instantiate the bloodhound suggestion engine
var dataSource = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "../" + autocompleteInfo.ControllerName + "/" + autocompleteInfo.MethodName + "?term=%QUERY&ts=" + (new Date().getTime()),
filter: function (res) {
var data = [];
data = $.map(res, function (item) {
return { label: item.Name, id: item.Id, autocompleteInfo: autocompleteInfo, cssClass: item.Class };
});
return data;
}
},
limit: 15,
name: 'typeaheadSourceCache',
ttl: 0,
ajax: {
cache: false
}
});
dataSource.initialize();
$("#" + autocompleteInfo.AutocompleteId).typeahead({
minLength: 3,
highlight: true,
autoselect: true
},
{
displayKey: 'label',
source: dataSource.ttAdapter(),
templates: {
suggestion: Handlebars.compile(
'<div class="searchItem {{cssClass}}">{{label}}</div>'
)
}
});
知道其他人在twitte可能會感興趣r typeahead社區也有同樣的問題,正在研究解決方案。例如,請參閱:https://github.com/twitter/typeahead.js/pull/703 – Phil
另請參閱https://github.com/twitter/typeahead.js/issues/564 –