Advertisement
metalx1000

jQuery Mobile Phone List

Jun 14th, 2015
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
  6. <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
  7. <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
  8.  
  9. <script>
  10.   var contacts = [
  11.     {"fname":"John", "lname":"Smith","phone":"(239)555-5555"},
  12.     {"fname":"Jim", "lname":"Parker","phone":"(239)555-3333"},
  13.     {"fname":"Tom", "lname":"Rock","phone":"(239)555-4322"}
  14.   ];
  15.  
  16.   contacts = sortByKey(contacts, 'lname');
  17.   function sortByKey(array, key) {
  18.       return array.sort(function(a, b) {
  19.           var x = a[key]; var y = b[key];
  20.           return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  21.       });
  22.   }
  23.  
  24.   $(document).ready(function(){
  25.     contacts.forEach(function(contact){
  26.       $("#list").append('<li>'+
  27.         '<a href="#" class="ui-btn">'+
  28. //        '<img src="res/iaff1.png" alt="FireFighter">'+
  29.         '<h3>'+contact.lname+', '+contact.fname+'</h3>'+
  30.         '<p>'+contact.phone+'</p>'+
  31.         '</a></li>');
  32.       $("#list").listview("refresh");
  33.     });
  34.   });
  35. </script>
  36. </head>
  37. <body>
  38.  
  39. <div data-role="page" id="pageone">
  40.   <div data-role="main" class="ui-content">
  41.     <h2>My Phonebook</h2>
  42.     <form class="ui-filterable">
  43.       <input id="myFilter" data-type="search">
  44.     </form>
  45.     <ul id="list" data-role="listview" data-filter="true" data-input="#myFilter" data-autodividers="true" data-inset="true">
  46.     </ul>
  47.   </div>
  48. </div>
  49.  
  50. </body>
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement