Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TJ autocomplete
$.get('https://cdnjs.cloudflare.com/ajax/libs/jquery.devbridge-autocomplete/1.2.21/jquery.autocomplete.min.js', function() {
$('.b-article-add-form__title__input input').autocomplete({
serviceUrl: 'https://api.tjournal.ru/2/club?category=news&sortMode=all&count=50',
minChars: 2,
//forceFixPosition: true,
noCache: true,
transformResult: function(res, orig) {
var data = JSON.parse(res);
var suggestions = [];
var origArr = orig.split(' ');
console.log(origArr);
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < origArr.length; j++) {
if (origArr[j].length > 1 && data[i].title.toLowerCase().indexOf(origArr[j].toLowerCase()) > -1) {
console.log(data[i].title)
suggestions.push(data[i].title);
//continue;
}
}
}
return { suggestions: suggestions };
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.