Procházet zdrojové kódy

Listing 6.5: iterating with $.each().

Frederic G. MARAND před 9 roky
rodič
revize
7c003c94e7
1 změnil soubory, kde provedl 11 přidání a 1 odebrání
  1. 11 1
      Chapter 6/06.js

+ 11 - 1
Chapter 6/06.js

@@ -9,7 +9,17 @@ $(document).ready(function () {
   $('#letter-b a').click(function (event) {
     event.preventDefault();
     $.getJSON('b.json', function (data) {
-      console.log(data);
+      var html = '';
+      $.each(data, function (entryIndex, entry) {
+        html += '<div class="entry">';
+        html += '<h3 class="term">' + entry.term + '</h3>';
+        html += '<div class="part">' + entry.part + '</div>';
+        html += '<div class="definition">';
+        html += entry.definition;
+        html += '</div>';
+        html += '</div>';
+      });
+      $('#dictionary').html(html);
     });
   });
 });