I have a view called "SectionView" with view parameter "SectionName". This view contains a flex repeater with dozens of instances of a view called "Icon". Each instance of "Icon" requires to be passed "SectionName". Therefore I simply need to bind the instance parameter to the view parameter and it works. However, I can't find a way to bind the parameter of every instance to the view parameter without doing it manually. Is there a way to automatically bind the parameter of all instances to the view parameter?
The instance "Icon" also has a parameter "index". I simply want to bind this value to it's instance number of the flex repeater. Is it possible to do so? (Similar to what you can achieve with template parameters in Vision)
Avoid using bindings with flex repeaters, especially when you have a dynamic number of instances.
Instead, use a script (either startup or a change script) to loop through and set those parameters on each instance. You could do something like this in the root startup script.
for i, inst in enumerate(self.getChild("FlexRepeater").props.instances):
inst.SectionName = nameOftheSection
inst.index = i
If repeater parameter is just being used to populate a template, with no dynamic parameter binding, meaning "SectionName" parameter of "icon" template is always going to be the same for all the instances, then ideally it should not be a parameter.
A possible work around will be to have it as a custom property of "icon" view and then bind it with the a custom session property and that property is in turn bound with the host view "SectionView" parameter "SectionName". This will simplify the whole structure of the binding.
As for the dynamic index, usage of the script as indicated by Kyler will do the trick.
How are you populating the instances in the Flex Repeater? If its dynamically, you can just add a
SectionName property to your
So, for example, if you're populating those instances based on a DB query or a list of tags, just do a script transform and add a
SectionName property like I said above. That's usually the route I take, but again, it depends on how you're populating the
Regarding your second question, there is already an
index parameter that gets passed in without you having to do anything. On your
Icon view, add an
index param, bind some label to it, and you'll see that it holds the right index value. Don't do it manually.
Here is my icon view (notice the
And here it is, showing up in my flex repeater automagically, without me having to pass in an index:
Edit: added reference to docs