Skip to content

Instantly share code, notes, and snippets.

@zzeneg
Created August 15, 2015 01:09
Show Gist options
  • Save zzeneg/3030a7aaecf73fc344ba to your computer and use it in GitHub Desktop.
Save zzeneg/3030a7aaecf73fc344ba to your computer and use it in GitHub Desktop.
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