You need to sign in to do that
Don't have an account?
Parteek Goyal 3
how to pass the record id from aura component to javascript controller on click on hyperlink
Hi All,
I want to pass the record id from component to javascript controller on click on account name hyperlink.
Please help me.
I want to pass the record id from component to javascript controller on click on account name hyperlink.
<aura:iteration items="{!v.searchResult}" var="acc" indexVar="count"> <tr> <td> <div class="slds-truncate">{!count + 1}</div> </td> <td> <!--a href="{!'/one/one.app?#/sObject/'+ acc.Id + '/view'}" width="400" height="400" target="_blank"--> <a onclick="{!c.openModel}"> <div class="slds-truncate">{!acc.Name}</div> </a> </td> <td> <div class="slds-truncate">{!acc.PersonEmail}</div> </td> </tr> </aura:iteration>
Please help me.
Please go through with below code, it may be helpful to you.
Do like this
In your component, assign the record Id to the button's Id
<aura:iteration items="{!v.newCases}" var="case">
<button type="button" onclick="{!c.showCaseDeleteModal}" id={!case.Id}>Delete</button>
</aura:iteration>
In your JS controller, capture the ID as as source of event:
showCaseDeleteModal: function(component, event, helper) {
var idx = event.target.id;
alert(idx); //here is your ID
});
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
All Answers
Use dataset in your anchor tag as below..
In your controller, get the clicked Account Name's Id as below..
Here, event.target belongs to anchor tag and event.currentTarget belongs to <div> tag inside the anchor tag. Since we have set 'data-id' with indexVar of iteration, this gives the element position in the array (searchResult).
By passing that index position to array, we can get the entire Var --> acc in controller and get whatever the field value we need (Here Id).
Let me know if this helps,
Lokesh
Please go through with below code, it may be helpful to you.
Do like this
In your component, assign the record Id to the button's Id
<aura:iteration items="{!v.newCases}" var="case">
<button type="button" onclick="{!c.showCaseDeleteModal}" id={!case.Id}>Delete</button>
</aura:iteration>
In your JS controller, capture the ID as as source of event:
showCaseDeleteModal: function(component, event, helper) {
var idx = event.target.id;
alert(idx); //here is your ID
});
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
Thanks for your quick reply.
It's working fine when i am using button instead of <a> tag. could you please help with <a> tag.
Thanks,
Parteek