javascript - Providing suggestions via Typeahead.js -


i have app uses bootstrap, jquery, typeahead.js , azure search. i'm trying use suggestions feature. in attempt this, have following:

var engine = new bloodhound({   datumtokenizer: bloodhound.tokenizers.whitespace,   querytokenizer: bloodhound.tokenizers.whitespace,   remote: {     url: 'https://my-app.search.windows.net/indexes/my-index/docs/suggest?api-version=2015-02-28',     prepare: function (settings) {       settings.type = 'post';       settings.contenttype = 'application/json; charset=utf-8';       settings.data = { search: query, suggestername: 'mysuggestions', top: 10 };                                                               return settings;     }   } });  $('#searchfield').typeahead([{   minlength: 5,   name: 'suggestions',   source: engine }]); 

when enter text searchfield, never see requests fired off azure search service in fiddler. @ same time, not see errors in console window. doing wrong?

a couple of things seem off me. first this:

$('#searchfield').typeahead([{   minlength: 5,   name: 'suggestions',   source: engine }]); 

might need more this:

$('.typeahead').typeahead(null,{   minlength: 5,   source: engine }); 

also prepare in engine function needs include "query" arg.

var engine = new bloodhound({   datumtokenizer: bloodhound.tokenizers.whitespace,   querytokenizer: bloodhound.tokenizers.whitespace,   remote: {     url: 'https://my-app.search.windows.net/indexes/my-index/docs/suggest?api-version=2015-02-28',     prepare: function (query,settings) {       settings.type = 'post';       settings.contenttype = 'application/json; charset=utf-8';       settings.data = { search: query, suggestername: 'mysuggestions', top: 10 };                                                               return settings;     }   } }); 

you can see working fiddle here.


Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -