-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
63 lines (53 loc) · 1.5 KB
/
index.js
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
57
58
59
60
61
62
63
// on-load
var originalMeats;
window
.fetch('meats.json') // fetch our meat data
.then((r) => r.json())
.then((response) => {
originalMeats = response.data;
putMeatInTable(originalMeats);
});
// functions
function searchMeats(term) {
const searchValue = document.getElementById('searchTerm').value;
clearTable();
putMeatInTable(
originalMeats.filter((m) =>
m.Meat.toLowerCase().includes(searchValue.toLowerCase())
)
);
}
function clearTable() {
var table = document.getElementById('meat-list');
var rowCount = table.rows.length;
// clear
for (var i = rowCount - 1; i > 0; i--) {
table.deleteRow(1);
}
}
function putMeatInTable(data) {
var tbody = document.getElementById('meat-list-body');
// populate
for (const meat of data) {
var row = tbody.insertRow();
var meatCell = row.insertCell();
meatCell.appendChild(document.createTextNode(meat.Meat));
var categoryCell = row.insertCell();
categoryCell.appendChild(document.createTextNode(meat.Category));
var tempCell = row.insertCell();
tempCell.appendChild(
document.createTextNode(
meat.CookerRange.Low + ' - ' + meat.CookerRange.High
)
);
var timeCell = row.insertCell();
timeCell.appendChild(document.createTextNode(meat.RelativeTime));
var targetTempCell = row.insertCell();
targetTempCell.appendChild(
document.createTextNode(
meat.TargetRange.Text ||
meat.TargetRange.Low + ' - ' + meat.TargetRange.High
)
);
}
}