我使用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 –