Access single views in a Flex Repeater

I am working with perspective and using a flex repeater.
I am repeating a simple view composed by a checkBox and 2 input parameters (text:sets the checkbox text when i create it, select:the the checbox value default to 0).
I am trying to return the text of all the selected checkbox in the view but i can’t find a way to access the single instances in the repeater.

You can’t access the individual instances of an instanced View, but if the instanced View has the param you’re using for the checkboxes set to Input/Output, then it will write that param back to the Flex Repeater, at which point you just need to loop through the instances, and check the checkbox param property; if it is now true (checked), then grab the text of that instance.

1 Like

Ok it works!
Thanks for the quick answer

1 Like

Struggling a bit with this one. How do I set the param of the instance view to have the checkbox property for selected?
Right now my view has two params:
parameterName
selected
In the checkbox component I’ve done a property binding between the view param parameterName to text and another property binding between view param selected and the selected property in the checkbox component.

I’m now trying to loop through the instances of the repeater and that works, but it does not work when i want to evalutate if the selected property is set or not.

My scrip looks like this:
for i in range(len(values.props.instances)):
if values.props.instances[i].selected == True:

The error messages is that the object does not have the attribute selected. I’ve tried different things but can’t seem to get it right.

Please educate me, I’m obviously misunderstanding how this is supposed to work

It would be a bit easier to help you if you posted a screenshot of the actual instance so that we could see what properties are in fact there. It would also be helpful to see the rest of your script because I have questions about what values refers to.

After trying this myself, I believe your approach is correct, and what is most likely occurring is you added an instance but have not added the expected selected property to that instance.

With this setup:
Screen Shot 2021-09-11 at 7.13.29 AM

And this script:

	instances = self.getSibling("FlexRepeater").props.instances
	for i in range(len(instances)):
		system.perspective.print('Index: {0}'.format(instances[i].index))

My logging displayed 07:13:12.303 [Browser Thread: 57533] INFO Perspective.Designer.Workspace - Index: 3.

Now, if I remove the index property from my instance, I get the following error:
AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'index'

Also, just as a point of cleaning up code, you don’t need to do direct comparisons to truth values (you also don’t need to not do them if you prefer your current approach). So you can change
if values.props.instances[i].selected == True: to if values.props.instances[i].selected:, assuming you expect that property to always be a boolean.

@cmallonee @PGriffith I know it’s been a while but I wanted to ask this since its related to what you posted above: do any parameters get passed into the flex repeater instances by default? In a Perspective column that is set to render a view, a bunch of them are, so I was wondering if that is the case for instances.

This would help me greatly with a program I’m working on right now.

If the View which is being instanced has params with default values defined, then each instance will receive those params with the default values as long as ViewNode.prop.inputBehavior is set to a value of “merge”. If ViewNode.props.inputBehavior is set to “replace”, then your instances will only receive the params you explicitly supply yourself as params for the instance.