I use Twitter typeahead.js 0.10.5 as a suggestion mechanism. It works great, with one exception, I cannot sort the list of offers the way I want.
As an example:
var data =[{"id":1,"value":"no need"}, {"id":2,"value":"there is no need"}, {"id":3,"value":"in the need of"}, {"id":4,"value":"all I need"}, {"id":5,"value":"need"}, {"id":6,"value":"needs"}, {"id":7,"value":"all he needs"}, {"id":8,"value":"he needs"}, {"id":9,"value":"they need"}, {"id":10,"value":"you need"}] var suggestion = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), queryTokenizer: Bloodhound.tokenizers.whitespace, local: data, limit: 20 }); suggestion.initialize(); $('.typeahead').typeahead({ hint: true, autoselect: true, highlight: true, minLength: 1 }, { name: 'suggestion', displayKey: 'value', source: suggestion.ttAdapter(), templates: { empty: [ '<div class="empty-message">', 'no suggestion in this map', '</div>' ].join('\n'), suggestion: Handlebars.compile('<p><span class="suggestion-text">{{value}}</span></p>') }
When I type โneed,โ I get sentences ordered by position in the array, but I would like it to be ordered by input, which means that the order should be โneededโ, โneededโ, โall I need need "... When typing" he "it should be" need "," all that he needs "," all that I need ", etc.
I know that Bloodhound has a sorter option, but I donโt know how to use it in this particular situation.