Can we dynamically build attribute name on run time in the lightning component?

Use case-

<aura:iteration items="{!v.attributeA}" var="key">
    {!v.attributeB + "!key" + .length}

So I am trying to use aura:iteration to loop through a list of string and within loop reference another attribute (type map). This map name has to use 'AttributeA : key' to form the correct name and then print the length of that map for that key.


AttributeA - "A, B"

AttributeB - "{OptionA : [item1, item2], OptionB : [item2, item3, item4]}"

Now, when looping through AttributeA, I need to reference AttributeB ("Option" + "A") to get number of items for OptionA (2 items), OptionB (3 items) etc.


No, LC does not allow this. Instead, you would need to build a List for aura:iteration to work with. You can handle this transformation of data in an aura:valueChange or aura:valueInit handler, as appropriate.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.