-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (49 loc) · 1.91 KB
/
script.js
File metadata and controls
56 lines (49 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
document.addEventListener("DOMContentLoaded", function () {
fetch("data.json")
.then((response) => response.json())
.then((data) => {
const tableBody = document.querySelector("#assignments-table tbody");
data.forEach((item) => {
const row = document.createElement("tr");
// Helper function to create and append a cell
function createCell(cellData) {
const cell = document.createElement("td");
cell.textContent = cellData.value;
if (cellData.class) {
cell.classList.add(cellData.class);
}
return cell;
}
// Create table cells
row.appendChild(createCell(item.sn));
row.appendChild(createCell(item.title));
row.appendChild(createCell(item.category));
const statusCell = createCell(item.status);
row.appendChild(statusCell);
const codeCell = document.createElement("td");
const codeLink = document.createElement("a");
codeLink.href = item.codeLink.value;
codeLink.textContent = "Code";
codeLink.classList.add("code-link");
if (item.codeLink.class) {
codeLink.classList.add(item.codeLink.class);
}
codeCell.appendChild(codeLink);
row.appendChild(codeCell);
const hostedCell = document.createElement("td");
const hostedLink = document.createElement("a");
hostedLink.href = item.hostedLink.value;
hostedLink.textContent = "Hosted Page";
hostedLink.classList.add("hosted-link");
if (item.hostedLink.class) {
hostedLink.classList.add(item.hostedLink.class);
}
hostedCell.appendChild(hostedLink);
row.appendChild(hostedCell);
const noteCell = createCell(item.note);
row.appendChild(noteCell);
tableBody.appendChild(row);
});
})
.catch((error) => console.error("Error fetching data:", error));
});