jquery- autocomplete

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$( "#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)
}