Providing domId for use in EmbeddedView

I made a screenshot from ICC recording stating this:

I guess this applies to situation where I embed a view. Just one.

What if I want to use a flex repeater and embed the same view n times. Does anyone have a advice how to identify those views in a repeater?

Thank you
Jakub

1 Like

In instances where you're using a View in an embedded manner, and you have components which will need to build their ID based off of some unknown unique value, you'll want to supply a unique value to the Embedded View (or instanced View) as a param, and then bind the domId value against that supplied param.

For Flex Repeaters, I usually just rely on the automatic index param passed in by the Flex Repeater, and bind against {view.params.index} + "_my_component". This will result in each instance within the Flex Repeater as having id attributes in the DOM of 0_my_component, 1_my_component, 2_my_component, etc.

You should use the same approach outside of a Flex Repeater, though you should target whichever named param you are passing in. Make sure to provide this param at the View level and provide a default value which does not make sense so that you know when it's being used appropriately.

For example:
I place a new param at the View level named my_param. I set the value of this param to "XXXX". Thus, when used by my component as part of the domId binding, I'll see a value of XXXX_my_component. This is obviously not a value I would expect and if I see this in use I've done something wrong. Now, when I use this same View in an embedded capacity I should make sure the embedded usage receives a param of my_param. If I supply the param value as "YES", I should expect the domId to resolve as "YES_my_component", and therefore I should expect an HTML id attribute of the same.

6 Likes

Didn't know this was a thing. Makes a few things simpler.

2 Likes

We call it out in the docs, but it's sort of a weird automatic property that makes it hard to define where it should go in the documentation.