display threads (poorly)

This commit is contained in:
agatha 2024-04-06 18:54:20 -04:00
parent 3e9f97e0e0
commit c3a88e187f

View File

@ -1,9 +1,32 @@
const apiUrl = 'http://localhost:8001';
function createTable(selector, items) {
const $table = $("<table></table>");
const $headerRow = $("<tr></tr>");
$.each(Object.keys(items[0]), function(i, key) {
const $th = $("<th></th>").text(key)
$headerRow.append($th);
});
$table.append($headerRow);
$.each(items, function (i, item) {
const $tr = $("<tr></tr>");
$.each(item, function(key, value) {
const $td = $("<td></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();