Closed abriginets closed 6 years ago
What do you mean by previousSuggestion
?
@tkirda I dare say that formatResult
runs some loop to iterate over the suggestions array. If I'm right then there should be an ability to call for an element which was iterated before current.
As a third parameter it passes suggestion index. So you can lookup previous suggestion in suggestions array. Suggestions are stored in suggestions
array on autocomplete instance.
I don't see usefulness of it, but if you need it you can access previous suggestion by looking up by index.
Excuse me for my silliness, but how could I access suggestions
inside of formatResult
? I could not access anythis by using $(this)
, this
or suggestions
. Much thanks in advance.
It is little bit ugly but should work:
let instance;
$('#input').autocomplete({
formatResult: (suggestion, value, i) => {
console.log('previous', instance.suggestions[i-1]);
return suggestion.value;
}
});
// Assign to variable which can be accessed inside formatResult
instance = $('#input').autocomplete();
Hello. Would you please add third parameter
previousSuggestion
to formatResult function? It would be very usefull to build child suggestions depending on previous suggestion value. Thanks.