Skip to main content
3 of 3
edited tags and retitled to better describe symptoms
Robert Sösemann
  • 38.2k
  • 29
  • 173
  • 508

Locker-Service safe passing of data from <a> and <lightning:xyz> to controller

In my lightning component I loop over records and display links to them:

1) Works, but is discouraged as it doesn't work in all places

<aura:iteration items="{!v.records}" var="record">
    <a href="{!'/' + stage.id}" />
</aura:iteration

2) Tried that but fails with:

Cannot mix expression and literal string in attribute value

<aura:iteration items="{!v.records}" var="record">
    <a onlick="sforce.one.navigateToSObject({!'/' + stage.id})" />
</aura:iteration

3) How to pass the recordId into myOwnNavigateToSObject()?

<aura:iteration items="{!v.records}" var="record">
    <a onlick="{!c.myOwnNavigateToSObject}" />
</aura:iteration

My preferred solution is to make 2) work as I see no use of an additional controller function that just delegates work to navigateToSObject().

Robert Sösemann
  • 38.2k
  • 29
  • 173
  • 508