1
我正在使用typeahead.js 0.11.1并尝试对来自远程源的结果进行排序。根据代码,应该有可能覆盖猎狗的默认排序功能。但我的排序功能从来没有被调用过。识别功能相同。如何将搜索结果排序在先头/血猎犬上?
这里是我的代码:
var bloodhoundSearchEngine = new Bloodhound({
// we do not need any tokenization cause this will be done on the server
datumTokenizer : function(d) {
return d;
},
queryTokenizer : function(q) {
return q;
},
sorter : function(itemA, itemB) {
console.log(itemA);
if (itemA.count < itemB.count) {
return -1;
} else if (itemA.count > itemB.count) {
return 1;
} else
return 0;
},
identify : function(item) {
console.log(itemA);
return item.value;
},
remote : {
url : '/suggest/?term=%term',
wildcard : '%term',
transform : function(response) {
return $.map(response.suggestItems, function(item) {
return {
value : item.value,
count : item.count
};
});
},
rateLimitBy : 'debounce',
rateLimitWait : 300
}
});
$('#typeaheadinput .typeahead')
.typeahead(
{
hint : true,
highlight : true,
minLength : 1
},
{
name : 'existing-names',
display : 'value',
limit : 20,
source : bloodhoundSearchEngine.ttAdapter()
});
有没有人在任何提示如何实现这一目标?
请问您可以在http://jsfiddle.net上创建演示吗? – Dhiraj
从来没有尝试过jsfiddle.net,但我找到了解决问题的方法。看到我的答案。 –