我使用TypeAhead和血犬一起尝试实现函数返回的可缓存结果。
背后的想法如下:
目前,每次用户更改输入时,我都会从结果函数直接调用TypeAhead:
jQuery(element).typeahead({
hint: true,
highlight: true, // This is to bold words that match the query
minLength: 3
}, {
name: "result",
displayKey: "value",
source: function (query, callback) {
typeaheadResults(query, callback);
}
});
但是,我想让BloodHound检索结果.我在这方面没有多少经验,我试过以下几点:
var bhResults = new Bloodhound({
datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.num); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: // What do I do here? function typeaheadResults needs the 'query'
});
typeaheadResults做了很多工作,所以我不能简单地使用血犬的remote
程序。
发布于 2014-07-30 16:24:56
我刚发现这个问题,我就这样解决了:
var bhResults = new Bloodhound({
datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.num); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: []
});
typeaheadResults(/* you don't need a query with bloodhound */, function(result){ bhResults.add(result); });
bhResults.initialize();
jQuery(element).typeahead({
hint: true,
highlight: true, // This is to bold words that match the query
minLength: 3
}, {
name: "result",
displayKey: "value",
source: bhResults.ttAdapter()
});
https://stackoverflow.com/questions/23929285
复制相似问题