How to copy variable's parameters in the Cycle <<for>>

Guys, I have sorted my cards using


Here how I did it:
[How to find generic object in array and return something]

But I’ve faced another problem.
Now I need those cards to be clickable, and on click a variable should be set as a copy of the clicked card’s parameters.
It wasnt a problem to make it clickable, but I still cant save parameters of the card in the variable.
Here’s my code:

<<set $routinecards.sort((a,b) => {
return -})>>
<<for _i=0;_i < $routinecards.length;_i++>>
<a data-passage="dayplan" data-setter="$dawn to $routinecards[_i]">
<img @src='"img/cards/"+ $routinecards[_i].type + "/" + $routinecards[_i].id + ".png"' style="position:relative; left:0; top:0;" height="`20%" width="20%">


<<set $s1 to {class: "routine", type: "s", id: 1}>>
<<set $n2 to {class: "routine", type: "n", id: 2}>>
<<set $routinecards to [$n2, $s1]>>

The problem is 100% here:

data-setter="$dawn to $routinecards[_i]"

I think maybe it doesn’t work because click happens after the cycle already created. So, maybe I just cant use this “for” method to reach the goal.
Maybe someone can help me to fix this, or teach me a better option :sweat_smile:

I found out that I shouldn’t use temporary _i variable, and it’s better to use $i in this case. But I still can’t build the link right, it doesn’t work

Yeah, you want a temporary variable _i and then use <<capture _i> ... <</capture>> to save it for later when the link actually happens. The docs actually have a <<for>> loop example that’s close enough to what you’re doing that you can probably figure it out?

If you use $i, it’ll appear to sort of work, but what’s happening is that by the time the link fires, $i will always have its final value from the very end of the loop.

1 Like

Nice, using <capture>> I was able to return data-setter="$dawn to $routinecards[_i].id". But it won’t to copy all card parameters when I’m trying it without .id data-setter="$dawn to $routinecards[_i]". Don’t know why it doesn’t want to work.

But I already can work with it, thanks a lot =) I’ll w8 some time before check it as solution. Also, I’m exploring this part of docs, thanks for this advice too =)