jquery- autocomplete Posted on 2018-12-08 17:44 12345678910111213141516171819202122232425262728293031$( "#jd-temp-name" ).autocomplete({ source: function (request, response) { $.ajax({ dataType: "json", type : 'Get', url: '<%= search_jd_temps_path%>', data:{ name: request.term, }, success: function(data) { console.log(data.professions) var items = []; $.each( data.professions, function(key, val){ items.push("<div class='result-item'>" + val.level3 + "<div class='subtitle'>" + val.level1 + "-" + val.level2 + "</div></div>") }); console.log(items) response(items); }, error: function(data) { console.log('fail') } }); }, }).data('ui-autocomplete')._renderItem = function(ul, item){ var expression = new RegExp(this.term,'gi') var result = item.label.replace(expression, "<span style='color: #ff4f4c!important;'>" + this.term + "</span>") return $("<li></li>").append(result).appendTo(ul) }