plantenClass OOP werkt volledig met sample data

This commit is contained in:
Renzo
2024-03-13 10:34:50 +01:00
parent 40947a7c46
commit c3ca61f82d
2 changed files with 9 additions and 8 deletions

Binary file not shown.

View File

@@ -36,7 +36,7 @@ class PlantGrid {
"id": 3, "id": 3,
"plantNaam": "Appel", "plantNaam": "Appel",
"plantensoort": "Groente", "plantensoort": "Groente",
"plantGeteelt": 1 "plantGeteelt": 0
}, },
{ {
"id": 4, "id": 4,
@@ -60,7 +60,7 @@ class PlantGrid {
"id": 7, "id": 7,
"plantNaam": "Groene", "plantNaam": "Groene",
"plantensoort": "Groente", "plantensoort": "Groente",
"plantGeteelt": 1 "plantGeteelt": 0
}, },
{ {
"id": 8, "id": 8,
@@ -72,19 +72,20 @@ class PlantGrid {
"id": 9, "id": 9,
"plantNaam": "yippie", "plantNaam": "yippie",
"plantensoort": "Groente", "plantensoort": "Groente",
"plantGeteelt": 0 "plantGeteelt": 1
} }
]; ];
const filteredData = dataHardObject.filter(plantObject => plantObject.plantGeteelt === 1); const filteredData = dataHardObject.filter(plantObject => plantObject.plantGeteelt === 1);
// Populate the grid with plant objects // Populate the grid with plant objects
filteredData.forEach((plantObject, index) => { filteredData.slice(0, 8).forEach((plantObject, index) => {
const plant = new Plant(plantObject); const plant = new Plant(plantObject);
const col = index % this.cols; const col = index % this.cols;
const row = Math.floor(index / this.cols); const row = Math.floor(index / this.cols);
this.grid[row][col] = plant; this.grid[row][col] = plant;
}); });
// Display the grid in the HTML table with id "planten" // Display the grid in the HTML table with id "planten"
this.displayGrid(); this.displayGrid();
@@ -113,7 +114,7 @@ class PlantGrid {
td.appendChild(article); td.appendChild(article);
itemCount++; itemCount++;
} if (rowIndex === this.rows -1 && colIndex === this.cols -1 & itemCount <= 7) { } else if (rowIndex === this.rows -1 && colIndex === this.cols -1 & itemCount <= 7) {
// Handle the "Add" button // Handle the "Add" button
const article = document.createElement("article"); const article = document.createElement("article");
const img = article.appendChild(document.createElement("img")); const img = article.appendChild(document.createElement("img"));