Advertisement
Guest User

example

a guest
Mar 22nd, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (() => {
  2. $('#viruses-button').click(() => {
  3.                 fetch('/viruses')
  4.                     .then((response) => response.json())
  5.                     .then((json) => {
  6.                        
  7.                         $('#choice-title').text('All Viruses');
  8.                         $('.container #data-container').remove();
  9.                         $('.container').append('<div id="data-container" class="mt-5"></div>');
  10.                        
  11.                         let table =
  12.                             `<table class="table">` +
  13.                             `<thead>` +
  14.                             `<tr class="text-center">` +
  15.                             `<th scope="col">#</th>` +
  16.                             `<th scope="col">Name</th>` +
  17.                             `<th scope="col">Magnitude</th>` +
  18.                             `<th scope="col">Released On</th>` +
  19.                             `<th scope="col">Actions</th>` +
  20.                             `</tr>` +
  21.                             `</thead>` +
  22.                             `<tbody>`;
  23.                        
  24.                         json.forEach((x, y) => {
  25.                            
  26.                             table +=
  27.                                 `<tr class="text-center">` +
  28.                                 `<th scope="row">${y + 1}</th>` +
  29.                                 `<td>${x.name}</td>` +
  30.                                 `<td>${x.magnitude}</td>` +
  31.                                 `<td>${x.releasedOn}</td>` +
  32.                                 `<td class="d-flex justify-content-between">` +
  33.                                 `<a class="btn btn-outline-secondary" href="/viruses/edit?id=${x.id}">Edit</a>` +
  34.                                 `<a class="btn btn-outline-secondary" href="/viruses/delete?id=${x.id}">Delete</a>` +
  35.                                 `</td>` +
  36.                                 `</tr>`;
  37.                         });
  38.                        
  39.                         table +=
  40.                             `</tbody>` +
  41.                             `</table>`;
  42.                        
  43.                         $('#data-container').append(table);
  44.                     });
  45.             });
  46.            
  47.             $('#cities-button').click(() => {
  48.                 fetch('/cities')
  49.                     .then((response) => response.json())
  50.                     .then((json) => {
  51.                        
  52.                         $('#choice-title').text('All Capitals');
  53.                         $('.container #data-container').remove();
  54.                         $('.container').append('<div id="data-container" class="mt-5"></div>');
  55.                        
  56.                         let table =
  57.                             `<table class="table">` +
  58.                             `<thead>` +
  59.                             `<tr class="text-center">` +
  60.                             `<th scope="col">#</th>` +
  61.                             `<th scope="col">Name</th>` +
  62.                             `<th scope="col">Latitude</th>` +
  63.                             `<th scope="col">Longitude</th>` +
  64.                             `</tr>` +
  65.                             `</thead>` +
  66.                             `<tbody>`;
  67.                        
  68.                         json.forEach((x, y) => {
  69.                            
  70.                             table +=
  71.                                 `<tr class="text-center">` +
  72.                                 `<th scope="row">${y + 1}</th>` +
  73.                                 `<td>${x.name}</td>` +
  74.                                 `<td>${x.latitude}</td>` +
  75.                                 `<td>${x.longitude}</td>` +
  76.                                 `</tr>`;
  77.                         });
  78.                        
  79.                         table +=
  80.                             `</tbody>` +
  81.                             `</table>`;
  82.                        
  83.                         $('#data-container').append(table);
  84.                     });
  85.             });
  86. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement