Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta charset="utf-8">
- <title>Custom Search</title>
- <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/redmond/jquery-ui.css">
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.js"></script>
- <script type="text/javascript" src="app.js"></script>
- <script type="text/javascript">
- </script>
- </head>
- <body>
- <input />
- </body>
- </html>
- $(function() {
- $.widget("custom.catcomplete", $.ui.autocomplete, {
- _renderMenu: function(ul, items) {
- var that = this,
- currentCategory = "";
- $.each(items, function(index, item) {
- if (item.name != currentCategory) {
- ul.append("<li class='ui-autocomplete-category'>" + item.name + "</li>");
- currentCategory = item.name;
- }
- that._renderItemData(ul, item);
- });
- }
- });
- $("input").catcomplete({
- delay: 0,
- source: function(request, response) {
- $.ajax({
- url: "data.json",
- dataType: "json",
- data: {
- term: request.term
- },
- success: function(data) {
- var cat_data = $.map(data, function(item) {
- return {
- name: item.name
- };
- });
- $("#searchfield").catcomplete({
- delay: 0,
- source: cat_data,
- minlength: 0
- });
- }
- });
- },
- minlength: 0
- });
- });
- [{
- "sku":12345,
- "name":"Car Batteries",
- "type":"HardGood",
- "price":0.50,
- "category":[
- {"id":"1","name":"Automobile"},
- {"id":"2","name":"Batteries"}]}
- {
- "sku":2345,
- "name":"Soap",
- "type":"Hygiene",
- "price":1.00,
- "category":[
- {"id":"3","name":"Hygiene"},
- {"id":"4","name":"Bathroom"}]}
- {
- "sku":56573,
- "name":"Camera",
- "type":"Photography",
- "price":700.50,
- "category":[
- {"id":"6","name":"Photography"},
- {"id":"7","name":"Gadgets"}]}
- {
- "sku":94893,
- "name":"iPhone Cable",
- "type":"Cables",
- "price":0.50,
- "category":[
- {"id":"19","name":"Cables"},
- {"id":"20","name":"Mobile"}]}]
Add Comment
Please, Sign In to add comment