Guest User

Untitled

a guest
Jan 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head lang="en">
  5. <meta charset="utf-8">
  6. <title>Custom Search</title>
  7.  
  8. <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/redmond/jquery-ui.css">
  9.  
  10. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
  11. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.js"></script>
  12. <script type="text/javascript" src="app.js"></script>
  13. <script type="text/javascript">
  14.  
  15. </script>
  16. </head>
  17.  
  18. <body>
  19. <input />
  20. </body>
  21.  
  22. </html>
  23.  
  24. $(function() {
  25. $.widget("custom.catcomplete", $.ui.autocomplete, {
  26. _renderMenu: function(ul, items) {
  27. var that = this,
  28. currentCategory = "";
  29. $.each(items, function(index, item) {
  30. if (item.name != currentCategory) {
  31. ul.append("<li class='ui-autocomplete-category'>" + item.name + "</li>");
  32. currentCategory = item.name;
  33. }
  34. that._renderItemData(ul, item);
  35. });
  36. }
  37. });
  38.  
  39. $("input").catcomplete({
  40. delay: 0,
  41. source: function(request, response) {
  42. $.ajax({
  43. url: "data.json",
  44. dataType: "json",
  45. data: {
  46. term: request.term
  47. },
  48. success: function(data) {
  49. var cat_data = $.map(data, function(item) {
  50. return {
  51. name: item.name
  52. };
  53. });
  54. $("#searchfield").catcomplete({
  55. delay: 0,
  56. source: cat_data,
  57. minlength: 0
  58. });
  59. }
  60. });
  61. },
  62. minlength: 0
  63. });
  64. });
  65.  
  66. [{
  67. "sku":12345,
  68. "name":"Car Batteries",
  69. "type":"HardGood",
  70. "price":0.50,
  71. "category":[
  72. {"id":"1","name":"Automobile"},
  73. {"id":"2","name":"Batteries"}]}
  74. {
  75. "sku":2345,
  76. "name":"Soap",
  77. "type":"Hygiene",
  78. "price":1.00,
  79. "category":[
  80. {"id":"3","name":"Hygiene"},
  81. {"id":"4","name":"Bathroom"}]}
  82. {
  83. "sku":56573,
  84. "name":"Camera",
  85. "type":"Photography",
  86. "price":700.50,
  87. "category":[
  88. {"id":"6","name":"Photography"},
  89. {"id":"7","name":"Gadgets"}]}
  90. {
  91. "sku":94893,
  92. "name":"iPhone Cable",
  93. "type":"Cables",
  94. "price":0.50,
  95. "category":[
  96. {"id":"19","name":"Cables"},
  97. {"id":"20","name":"Mobile"}]}]
Add Comment
Please, Sign In to add comment