0
我正在使用Rails創建我的應用程序,但實現了搜索的javascript。這是我的Algolia自動完成功能。我與Algolia一起參與免費('Hacker')計劃,並且我想添加一個頁腳。是否有捷徑可尋?我在下面(我發現在:https://github.com/algolia/autocomplete.js/blob/master/README.md)不起作用。Algolia添加頁腳到javascript自動完成搜索結果下拉列表
var client = algoliasearch("<%= ENV['ALGOLIA_API'] %>", "<%= ENV['ALGOLIA_SECRET'] %>");
var index = client.initIndex('User');
//initialize autocomplete on search input (ID selector must match)
autocomplete('#aa-search-input',
{ hint: false }, [{
source: autocomplete.sources.hits(index, {hitsPerPage: 5}),
//value to be displayed in input control after user's suggestion selection
displayKey: function(suggestion) { return suggestion.first_name + " " + suggestion.last_name},
//hash of templates used when rendering dataset
templates: {
//'suggestion' templating function used to render a single suggestion
suggestion: function(suggestion) {
var link = "<form action='<%= ENV['HOST'] %>users/" + suggestion.id + "/friend_requests' method='post' id='addfriend' style='color: lightgreen'> <input name='authenticity_token' value='<%= form_authenticity_token %>' type='hidden'> <button type='submit' name='user_id' value='" + suggestion.id + "' class='btn-link'>Add</button></form>";
var card = "<span>" + "<img src=<%= ENV['CLOUDINARY_SECOND_URL'] %>" + suggestion.photo.path + " alt='' class='avatar'> " +
suggestion._highlightResult.first_name.value + " " + suggestion._highlightResult.last_name.value + "</span><span>" + link +"</span>";
return card
}
}
footer: '<span class="branding">Powered by <img src="https://www.algolia.com/assets/algolia128x40.png" /></span>'
}]).on('autocomplete:selected', function(event, suggestion, dataset) {
var url = "<%= ENV['HOST'] %>users/";
window.location.assign(url + suggestion.id)});
通過「不工作」,我假設你的意思是:「頁腳不出現」? – evadeflow