-
As the title, in my case I need a Linked List (to represent an interactive flowchart) But I'm not sure how I can iterate over it to display it as html elements. I know that I can with either a while loop or a recursive function, but how to do so with Svelte? I really don't want to use React ... |
Beta Was this translation helpful? Give feedback.
Answered by
brunnerh
Sep 7, 2024
Replies: 1 comment 1 reply
-
You can wrap the iteration logic in a generator function and use that in E.g. if the items have the shape function* iterate(list) {
let current = list;
while (current != null) {
yield current.value;
current = current.next;
}
} {#each iterate(list) as item}
<div>{item}</div>
{/each} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Saad5400
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can wrap the iteration logic in a generator function and use that in
#each
.E.g. if the items have the shape
{ value, next }
and end withnext
beingnull
:REPL