我在我的web應用程序中使用typeahead.js 0.10.5。出於一些奇怪的原因,通過遠程工作獲取建議,而預取損壞。這裏有一些非明顯和奇怪的事情。根據開發控制檯和Chrome的網絡監視器,它甚至沒有對頁面加載進行查詢。當然,當我開始輸入時,它會進行查詢。Typeahead.js遠程工作,但預取不
這真的讓我難住 - 我在這裏做錯了什麼?
// Instantiate the Bloodhound suggestion engine
var tags = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/tags/tags/search.json?q=%QUERY',
filter: function (taglist) {
// Map the remote source JSON array to a JavaScript object array
return $.map(taglist, function (tag) {
console.log(tag);
return {
value: tag.tag
};
});
}
},
prefetch: {
url: '/tags/tags/search.json?q=',
filter: function (taglist) {
// Map the remote source JSON array to a JavaScript object array
return $.map(taglist, function (tag) {
console.log(tag);
return {
value: tag.tag
};
});
},
}
});
// Initialize the Bloodhound suggestion engine
tags.initialize();
// Instantiate the Typeahead UI
$('#search-tags').typeahead(null, {
displayKey: 'value',
source: tags.ttAdapter(),
hint: true,
highlight: true
});
嘗試從瀏覽器的localStorage中刪除條目並重新開始。 – mdarwi 2015-02-05 21:06:55
嗯,我試着使用Chrome的「刪除最近的活動」,並沒有這樣做,但手動刪除本地存儲中的密鑰後,它的工作。發佈這個答案,我會標記爲正確的。 – schnauss 2015-02-05 21:15:38