Addition to tutorial: Calling a function in an "each" block
See original GitHub issueThe tutorial/documentation should have an example of calling a function inside an each block to do some additional processing. This is non-intuitive so putting it in the tutorial would be very helpful.
e.g.
<script>
function dosomething(item) {
var dict = {};
// Put original object into the dictionary
dict.item = item;
// Do some processing and put various results in the dictionary to be used in the loop.
dict.result = "success";
dict.count = 12;
return dict;
}
</script>
{#each list as item}
{#each [dosomething(item)] as val}
<div>{val.result} {val.item} {val.count}</div>
{/each}
{/each}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Functions — reusable blocks of code - Learn web development
This function draws 100 random circles inside a <canvas> element. Every time we want to do that, we can just invoke the function...
Read more >TwinCAT 3 Tutorial: Writing your own Functions and ...
A program is like a function block (it has internal state), but there is only one global copy of each program, so you...
Read more >How to Define and Call a Function in PHP
Functions reduces the repetition of code within a program — Function allows you to extract commonly used block of code into a single...
Read more >Functions
In the example above, main begins by declaring the variable z of type int , and right after that, it performs the first...
Read more >How To Define and Call Functions in Go
A function is a section of code that, once defined, can be reused. Functions are used to make your code easier to understand...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is there a reason to do it that way instead of just
Here’s a REPL example of this style: https://svelte.dev/repl/3d071e514c7641c580980c48dd1b6665?version=3.14.0
Sure but it’s not in the TUTORIAL.