Dynamic Expression?

I have a custom param on my view that’s an array. I have some buttons where I want to iterate the array and show the values on the screen. I have a label on the screen with an expression showing the value, the problem is that I cant figure out to to make the expression dynamic so I can iterate.

I got it working by changing the expression to now() and then using a script transform to build the path and get the value. Is that the right way or do you prefer something else? Thanks!

Does {view.param.datavalue}[{view.custom.selectedIndex}] or something along that line not work?
You could always build the path to the property using property, something like property(stringFormat("view.params.dataValue[%d]", {view.custom.selectedIndex}))

Create an custom.index tag

On your buttons you increment and reset the index using the array length as a boundary

def runAction(self, event):
	options = len(self.view.custom.lunch)
	if options > 0:
		self.view.custom.index = (self.view.custom.index + 1) % options

On your label you point it to the overall array and the index number to select the value you want

property, not tag.

Unnecessary and expensive, expressions allow dynamic indexes when accessing members in an array. Just make the binding an expression binding of {view.custom.lunch}[{view.custom.index}].

1 Like

Valid point, I switched the binding type