Guest User

Untitled

a guest
Jul 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. @index.document("1").add({:text => "London England"})
  2.  
  3. $("#query").data("autocomplete")._renderItem = function(ul, item) { .. }
  4.  
  5. get '/index/' do
  6. term = params['term']
  7.  
  8. #Query IndexTank index using the IndexTank::Client
  9.  
  10. #Parse index search results and return an array of the suggestions as JSON
  11. end
  12.  
  13. <form id="search_form" action="/" method="POST">
  14. <input id="search_field" name="search_field" type="text">
  15. </form>
  16.  
  17. $(document).ready(function(){
  18. $("#search_field").autocomplete({
  19. source: function(request, response) {
  20. $.ajax({
  21. url: "/index/",
  22. dataType: 'json',
  23. data: { term: request.term },
  24. success: function(data) {
  25. response($.map(data, function(item) {
  26. return {label: __highlight(item, request.term),
  27. value: item};
  28. }));
  29. }
  30. });
  31. },
  32. minLength: 2
  33. })
  34. .data( "autocomplete" )._renderItem = function( ul, item ) {
  35. // only change here was to replace .text() with .html()
  36. return $( "<li></li>" )
  37. .data( "item.autocomplete", item )
  38. .append( $( "<a></a>" ).html(item.label) )
  39. .appendTo( ul );
  40. };
  41. });
  42.  
  43. function __highlight(s, t) {
  44. var matcher = new RegExp("("+$.ui.autocomplete.escapeRegex(t)+")", "ig" );
  45. return s.replace(matcher, "<strong>$1</strong>");
  46. }
Add Comment
Please, Sign In to add comment