Update the value in a variable within a loop

I have a loop and want to set the value of a variable from within that loop. I’m showing a list of records but want to be able to show a button if the previous item in the loop contains a particular value. So I’m thinking that a variable is the best way. I can set it to 1 if the value is what I’m looking for, then the next item will show the button if the value is 1 and then reset it back to 0.

The showing if value is 1 is straightforward but I can’t see how I can change the variable value within the loop.

If the main issue is showing the button, could you check the value in the previous record like this:
dmx-show="serverconnect1.data.query[$index-1].myField == 1"
… without using and have to reset a variable etc.?

2 Likes

Genius! And this unlocks something I didn’t know about. Works perfectly.

Huge thanks @TomD.

Great - I’m glad that helped. There’s a lot to unlock in Wappler!

1 Like