Created
November 25, 2017 16:24
-
-
Save nnagornyy/a670afd718972cbefeca344a3de006f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.js-search-autocomplete').autocomplete({ | |
appendTo: "header .search-results", | |
source: function (request, response) { | |
$.ajax({ | |
url: "/", | |
data: { q: request.term, maxResults: 10,ajax_call:'y' }, | |
dataType: "json", | |
method: 'POST', | |
success: function (data) { | |
$('.search-results').addClass('show'); | |
console.log(data); | |
response($.map(data, function (item) { | |
return { | |
value: item.name, | |
link: item.link, | |
picsrc: item.picsrc, | |
price: item.price, | |
oldprice: item.oldprice | |
}; | |
})) | |
} | |
}) | |
} | |
}).data("ui-autocomplete")._renderItem = function (ul, item) { | |
console.log(item) | |
var inner_html = '<a href="'+item.link+'"><span class="pic"><img src="'+item.picsrc+'" width="" height="" alt=""></span><span class="name">'+item.value+'</span><span class="price"><span class="old-price">'+item.oldprice+'</span><strong>'+item.price+'</strong></span></a>'; | |
return $("<li></li>") | |
.data("item.autocomplete", item) | |
.append(inner_html) | |
.appendTo(ul); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment