tom*_*nek 2 ruby jquery-ui autocomplete ruby-on-rails
我有使用 jQuery UI 自动完成插件的搜索建议自动完成功能。 http://jqueryui.com/autocomplete/
但是如何在结果弹出项的底部添加其行为类似于 Quora(见下文)。
Javascript
$("#question_search").autocomplete({
source:$('#question_search').data('source'),
html: true,
appendTo: "#search_results",
select: function( event, ui ) {
window.location=ui.item.value;
return false;
},
focus: function( event, ui ) { },
open: function( event, ui ) { });
Run Code Online (Sandbox Code Playgroud)
看法
<div id="question_search_form">
<input type="text" id="question_search" data-source="<%= new_search_url %>" />
<div id="search_results"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
例子

我建议覆盖_renderMenu然后简单地在列表项中附加一个锚点。
爪哇脚本:
$( "#question_search" ).autocomplete({
source:$('#question_search').data('source'),
html: true,
appendTo: "#search_results",
select: function( event, ui ) {
window.location=ui.item.value;
return false;
},
focus: function( event, ui ) { },
open: function( event, ui ) { }
}).data( "autocomplete" )._renderMenu = function( ul, items ) {
$.ui.autocomplete.prototype._renderMenu.apply( this, [ul, items] );
ul.append( '<li><a href="/search/'+ this.term + '">Search: '+ this.term + '</a></li>' );
};
Run Code Online (Sandbox Code Playgroud)
演示:http : //jsfiddle.net/4pk3V/42/
希望这可以帮助!如果您有任何问题,请告诉我!