Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @index.document("1").add({:text => "London England"})
- $("#query").data("autocomplete")._renderItem = function(ul, item) { .. }
- get '/index/' do
- term = params['term']
- #Query IndexTank index using the IndexTank::Client
- #Parse index search results and return an array of the suggestions as JSON
- end
- <form id="search_form" action="/" method="POST">
- <input id="search_field" name="search_field" type="text">
- </form>
- $(document).ready(function(){
- $("#search_field").autocomplete({
- source: function(request, response) {
- $.ajax({
- url: "/index/",
- dataType: 'json',
- data: { term: request.term },
- success: function(data) {
- response($.map(data, function(item) {
- return {label: __highlight(item, request.term),
- value: item};
- }));
- }
- });
- },
- minLength: 2
- })
- .data( "autocomplete" )._renderItem = function( ul, item ) {
- // only change here was to replace .text() with .html()
- return $( "<li></li>" )
- .data( "item.autocomplete", item )
- .append( $( "<a></a>" ).html(item.label) )
- .appendTo( ul );
- };
- });
- function __highlight(s, t) {
- var matcher = new RegExp("("+$.ui.autocomplete.escapeRegex(t)+")", "ig" );
- return s.replace(matcher, "<strong>$1</strong>");
- }
Add Comment
Please, Sign In to add comment