Hi, I would like to use a "complex" for loop to build my component from an array of typescript objects, but I cannot wrap my head around it. This is my situation:
class Thumbnail {
category: VideoCategory;
link: string;
src: string;
title: string;
text: string;
constructor(
category: VideoCategory,
link: string,
src: string,
title: string,
text: string
) {
this.category = category;
this.link = link;
this.src = src;
this.title = title;
this.text = text;
}
}
export enum VideoCategory {
animation = "Animation",
nature = "Nature",
sport = "Sport",
movies = "Movies",
}
Then in my component I would like to do something along the lines of:
---
// imports ...
const thumbnails: Thumbnail[] = [] // populated from imports
---
<Layout>
<div class="container">
{
for (const category of Object.keys(VideoCategory)) {
for (const thumbnail of thumbnails) {
<div>
<h2>{category}</h2>
if (thumbnail.category == VideoCategory[category]) {
<div class="container">
<a href={thumbnail.link}>
<img src={thumbnail.src} alt="" />
<span class="title">{thumbnail.title}</span>
<span class="text">{thumbnail.text}</span>
</a>
</div>
}
</div>
}
}
}
</div>
</Layout>
Is it possible to use if and normal for loops in a component?