Skip to main content
Tweeted twitter.com/StackSalesforce/status/870691159240200193
edited tags and retitled to better describe symptoms
Link
Robert Sösemann
  • 38.2k
  • 29
  • 173
  • 508

How to use navigateToSObject in onclick handlers directly Locker-Service safe passing of data from <a> and correctly<lightning:xyz> to controller

added 11 characters in body
Source Link
Robert Sösemann
  • 38.2k
  • 29
  • 173
  • 508

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="navigateToSObjectonlick="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().

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="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().

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().

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

How to use navigateToSObject in onclick handlers directly and correctly

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="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().