|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | + <title>Listview Filter & Autodividers - jQuery Mobile Demos</title> |
| 7 | + <link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css"> |
| 8 | + <link rel="stylesheet" href="../_assets/css/jqm-demos.css"> |
| 9 | + <script src="../../../js/jquery.js"></script> |
| 10 | + <script src="../_assets/js/jqm-demos.js"></script> |
| 11 | + <script src="../../../js/"></script> |
| 12 | + <script> |
| 13 | + $( document ).ready( function() { |
| 14 | + $( "#autocomplete" ).listview({ |
| 15 | + filter: true |
| 16 | + }); |
| 17 | + |
| 18 | + $( "#autocomplete" ).on( "listviewbeforefilter", |
| 19 | + function( e, data ) { |
| 20 | + var $ul = $( this ), |
| 21 | + $input = $( data.input ), |
| 22 | + value = $input.val(), |
| 23 | + html = ""; |
| 24 | + $ul.html( "" ); |
| 25 | + if ( value && value.length > 2 ) { |
| 26 | + $ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>"); |
| 27 | + $ul.listview( "refresh" ); |
| 28 | + $.ajax({ |
| 29 | + url: "http://gd.geobytes.com/AutoCompleteCity", |
| 30 | + dataType: "jsonp", |
| 31 | + crossDomain: true, |
| 32 | + data: { |
| 33 | + q: $input.val() |
| 34 | + } |
| 35 | + }). |
| 36 | + then( |
| 37 | + function( response ) { |
| 38 | + $.each( response, function( i, val ) { |
| 39 | + html += "<li>" + val + "</li>"; |
| 40 | + }); |
| 41 | + $ul.html( html ); |
| 42 | + $ul.listview( "refresh" ); |
| 43 | + } |
| 44 | + ) |
| 45 | + } |
| 46 | + } |
| 47 | + ); |
| 48 | + }); |
| 49 | + </script> |
| 50 | +</head> |
| 51 | +<body> |
| 52 | +<div data-role="page"> |
| 53 | + |
| 54 | + <div data-role="header" data-theme="f"> |
| 55 | + <h1>Listview Autocomplete</h1> |
| 56 | + <a href="../" data-icon="home" data-iconpos="notext" data-ajax="false">Home</a> |
| 57 | + </div><!-- /header --> |
| 58 | + |
| 59 | + <div data-role="content"> |
| 60 | + |
| 61 | + <div class="content-primary"> |
| 62 | + |
| 63 | + <div data-demo-html="true" data-demo-js="true"> |
| 64 | + <ul id="autocomplete" data-filter-theme="d"></ul> |
| 65 | + </div><!--/demo-html --> |
| 66 | + |
| 67 | + |
| 68 | + </div><!--/content-primary --> |
| 69 | + |
| 70 | + </div><!-- /content --> |
| 71 | + |
| 72 | + <div class="jqm-footer"> |
| 73 | + <p class="jqm-version"></p> |
| 74 | + <p>© 2012 jQuery Foundation and other contributors</p> |
| 75 | + </div><!-- /jqm-footer --> |
| 76 | + |
| 77 | +</div><!-- /page --> |
| 78 | + |
| 79 | +</body> |
| 80 | +</html> |
0 commit comments