Skip to content

[templates] Item variable shadowed by second repeat, how to solve? #36

@herrKlein

Description

@herrKlein

Hi,

I need the item variable from the 1st loop, but is is shadowed by the 2nd loop.
Can I name the 'item' variable. I can't find it in the documentation.

<template>
<template type="repeat" repeat="{{ currentItem.responses }}"> <!-- 1 -->
   
   {{ item.text }}
   <!-- ⇧ ------ item is the response -->

   <test-scoring-buttons .item="{{ currentItem }}">
      <template>
         <template type="repeat" repeat="{{ scores }}"> <!-- 2 -->
            
            <!-- I need the response in the item of the first loop in the name variable -->
            <input type="radio" name="{{ __item__.identifier }}" ?checked="{{item == score}}"  />
           
            <span>{{item}}</span>
         </template>
      </template>
   </test-scoring-buttons>
</template>
</template>

ChatGPT suggests the as attribute, but that does not seem to work.

...
      <template type="repeat" repeat="{{ scores }}" as="score">
        <!-- Now 'score' is used inside this loop, and 'item' still refers to the response from the outer loop -->
        <input type="radio" name="{{ item.identifier }}" ?checked="{{item == score}}" />
        <span>{{ score }}</span>
      </template>
...

Is there a way to solve this?

Originally posted by @herrKlein in #35

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions