Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function openBooks(author)
- {
- var tbl=document.getElementById("authorsTable");
- tbl.parentNode.removeChild(tbl);
- $.getJSON('books', function(data) {
- var table = $('<table border="1"></table>');
- $(table).append('<tr><th>Id</th><th>Title</th><th>Genre</th><th>Author</th></tr>');
- $.each(data, function(key, value) {
- var authorCell=$('<td></td>');
- var actualAuthor;
- $.each(value['authors'], function(authorIndex, authorValue){
- $(authorCell).append(authorValue['name']);
- actualAuthor=authorValue['name'];
- });
- if(author===actualAuthor){
- var row = $('<tr></tr>');
- var idCell = $('<td>' + value['bookId'] + '</td>');
- var titleCell = $('<td>' + value['title'] + '</td>');
- var genresCell = $('<td>' + value['genres'] + '</td>');
- $(row).append(idCell);
- $(row).append(titleCell);
- $(row).append(genresCell);
- $(row).append(authorCell);
- $(table).append(row);
- }
- });
- $('#content').append(table);
- });
- }
- <script>
- $.getJSON('authors', function(data) {
- var table = $('<table id="authorsTable" border="1"></table>');
- $(table).append(
- '<tr><th>Name</th><th>Nationality</th><th>Birth date</th></tr>');
- $.each(data, function(key, value) {
- var row = $('<tr></tr>');
- var link
- var nameCell = $('<td id="authorId" onclick="openBooks(' + "'" + value['name'] + "'" + ')">' + value['name'] + '</td>');
- var nationCell = $('<td>' + value['nationality'] + '</td>');
- var birthDateCell = $('<td>' + converDate(value['birthDate']) + '</td>');
- $(row).append(nameCell);
- $(row).append(nationCell);
- $(row).append(birthDateCell);
- $(table).append(row);
- });
- $('#content').append(table);
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment