From c3a88e187fd7f4aa3683c67e80af9311ee0017c4 Mon Sep 17 00:00:00 2001 From: agatha Date: Sat, 6 Apr 2024 18:54:20 -0400 Subject: [PATCH] display threads (poorly) --- frontend/src/assets/js/app.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/frontend/src/assets/js/app.js b/frontend/src/assets/js/app.js index fc383b2..83dd057 100644 --- a/frontend/src/assets/js/app.js +++ b/frontend/src/assets/js/app.js @@ -1,9 +1,32 @@ const apiUrl = 'http://localhost:8001'; +function createTable(selector, items) { + const $table = $("
"); + const $headerRow = $(""); + + $.each(Object.keys(items[0]), function(i, key) { + const $th = $("").text(key) + $headerRow.append($th); + }); + $table.append($headerRow); + + $.each(items, function (i, item) { + const $tr = $(""); + $.each(item, function(key, value) { + const $td = $("").text(value); + $tr.append($td); + }); + $table.append($tr); + }); + + console.log($table); + + $(selector).append($table); +} function getCatalog() { $.getJSON(apiUrl + "/catalog", function (resp) { - console.log(resp) - }) + createTable('.posts', resp); + }); } $( document ).ready(function() { getCatalog();