i´m struggling the whole day. My typeahead search expression works perfect with remote json data. But when i try to use the same json data as prefetched data, the suggestion is empty. After hitting the first sign i get the predefined message "unable to find anything t..." for an empty result.
Here is my script:
function initialTypeaheadTest(){
var mo_selector = $('*[data-moT="mysearch"]');
var engine = new Bloodhound({
limit: 10
,prefetch: {url:'/api/action/getjsontest'}
//,remote: {url:'/api/action/getjsontest'}
,datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name')
,queryTokenizer: Bloodhound.tokenizers.whitespace
});
engine.clearPrefetchCache(); // only for test purposes
engine.initialize();
mo_selector.typeahead(
{
hint: true,
highlight: true,
minLength: 1
}, {
name: 'engine',
displayKey: 'name',
source: engine.ttAdapter(),
templates: {
empty: [
'<div class="empty-message">',
'unable to find anything that match the current query',
'</div>'
].join('\n'),
suggestion: Handlebars.compile([
'<div id="{{value}}"><p style="max-height:100%;"><strong>{{title}}</strong></p>',
'<span style="font-size:12px;">{{year}}</span></div>'
].join(''))
}
});
}
and thats my json:
[{
"year":"02 Feb 2013 at 00:40 by anonymous",
"title":"JavaScript HTML DOM Changing HTML Content",
"value":"1",
"tokens":["JavaScript", "HTML", "DOM", "Changing", "HTML", "Content"]
},{
"year":"02 Feb 2013 at 00:42 by anonymous",
"title":"WDR.de",
"value":"2",
"tokens":["WDR.de"]
},{
"year":"02 Feb 2013 at 00:46 by anonymous",
"title":"Nachrichten, aktuelle Schlagzeilen und Videos - n-tv.de",
"value":"3",
"tokens":["Nachrichten", "aktuelle", "Schlagzeilen", "und", "Videos", "n", "tv.de"]
},{
"year":"02 Feb 2013 at 00:55 by anonymous",
"title":"JavaScript RegExp Object",
"value":"5",
"tokens":["JavaScript", "RegExp", "Object"]
},{
"year":"15 Feb 2013 at 23:24 by anonymous",
"title":"DotnetNuke Module Car Listing Module",
"value":"8",
"tokens":["DotnetNuke", "Module", "Car", "Listing", "Module"]
},{
"year":"08 Feb 2014 at 01:08 by advertiser",
"title":"Empfehlung",
"value":"1000",
"tokens":["Empfehlung"]
}]
original path: mattopen.com/api/action/getjsontest
for me, all looks good. The json data is well formed. All strings (e.g. in tokens) are quoted in double quotes as well. Why is remote data working but prefetch not?
can someone point me in the right direction? thanks