Dynamically set parameter bindings on flex repeater instances

Hello everyone,

I have a Perspective View with some parameters. Inside this view, there is a Flex Repeater. I want to dynamically bind the parameters of the view to every instance of the Flex Repeater. I know you can manually bind the view parameters with the instance parameters, but I want to know if there is a way to do it dynamically, because I haven't found one. Thank you for your help.

Doing it manually could be very time-consuming if one has many instances within the Flex Repeater.

What data are you binding? If it's tag data then it may make more sense to pass a tag path to your instances and have an indirect tag binding in the instance view.

Otherwise you'd probably have to copy the view xml, load it into a file and then program something to parse the file and insert the binding definition into each item of the instance array. Then you would take that new xml from the file and paste it back into the designer.

If you are looking for something that allows you to dynamically bind during runtime, that doesn't exist. The next best thing is to include the data you want to pass to the instances when generating your instance array, and utilize message handlers to send data back 'upwards' from the instances.

How are you determining the instances in your repeater? This should be pretty simple to do, I would think, unless I'm completely misunderstanding you.

Step 0: On the view that's getting repeated, create a view parameter (I'll call it viewTest in this example).

Step 1: Create a parameter on the view that holds the repeater (I'll call it test for this example).

Step 2: Create a binding on the instances property of your repeater - make it a property binding and set the property to the test view parameter.

Step 3: Add a script transform to dynamically generate the instances objects. This might be coming from a database, tag or some other place. You could also create a custom property (you probably should do it this way) and just call the custom property from the script transform.

Step 4: Loop over each instance and set the viewTest = test.

Example:

# this is the script transform
objs = self.view.custom.objsFromDB    # list of dicts, example
for obj in objs:
    obj["viewTest"] = self.view.param.test

return objs

Any time your view parameter changes, your repeater instances should also get the new value.

EDIT: Example gif:
java_tvcTKRJna2

1 Like

image

These are the parameters on the main view, and depending on which button you click, these parameters can change.

The view that is being repeated has the indirect tag binding.

That is what I'm doing.

Can you show me the binding on props.instances?

I'm assuming the number of instances will vary? If so then you'll probably have to follow the process mentioned by @YF129701.

You could also have the main view push its params into a session custom property, and then let your instance views bind to that directly. This method can get convoluted fast if you have lots of views with varying data.

Yep, here it is. Again, its not realistic because I don't know how you're determining the number of instances, but it should get you close. Just replace line 2 with what you need:

def transform(self, value, quality, timestamp):
	ls = [{"item": x} for x in range(5)]		# simulate "dynamic" repeater instances
	
	for l in ls:
		l["viewTest"] = self.view.params.test
		
	return ls

And here is the view being repeated:

image

1 Like

Correct!

This is the setup I ended up with:

def transform(self, value, quality, timestamp):
	# Create a list of dictionaries with instanceStyle and instancePosition
	ls = [{"instanceStyle": {}, "instancePosition": {}} for x in range(5)]
	
	# Iterate through the list and update each dictionary with the new values
	for l in ls:
	    l.update(value)
	
	# Return the updated list
	return ls