Create a dynamic variable in oh-repeater

Hi,

I’m working on a custom widget in which I use an oh-repeater to list all light items as a list of custom made rows. In each row, I’m trying to add a button that is gonna work as an extender to the properties of the said light in the row (clicking on the button expand the row to have sliders for dimmers and colors).

My current issue is if I make a button with the variable “moreInfo”, all the rows will then expands, not just the row in which the button has been clicked. I then tried to use the “item.loop.label” as the variable name but I’m not sure of the right way to use the current iteration of the item as a variable or if it is doable. I’ve tried many syntaxes but none have worked so far. Is there a way to create a variable that will dynamically change for each loop iteration?

Thanks for the help!

 - component: oh-repeater
   config:
     for: item
     sourceType: itemsWithTags
     itemTags: Light
   slots:
      default:
          - component: f7-row
            config:
            slots:
              - component: oh-button
                config:
                  action: variable
                  actionVariable: =loop.item.label
                  actionVariableValue: more
              - component: f7-row
                   visible: '=(vars.loop.item.label === "more")'

In addition to using dot indexing X.Y you can use brackets to specify the different keys in objects and that allows you to pass variables as the keys. That’s what you’ll need to use in this case. Setting

 actionVariable: =loop.item.label

does not create the variable vars.loop.item.label it creates the variable vars.whateverthelabelis. So if the item label is “Basement Light” the variable is vars['Basement Light']. Since you still have access to loop.item.label, you just put that in the brackets when you need to call that particular variable

visible: '=(vars[loop.item.label] === "more")'

This will fail if, for some reason, any of your items have the same label. So it might even be better to use the item name instead of the item label, as that must be unique by definition.

Thanks Justin, that was the syntax I was trying to find for so long!
Also, good suggestion to use the item name instead of label.