Activity Forums Salesforce® Discussions Can we change javascript onclick button to Salesforce lightning component attribute?

  • PRANAV

    Member
    January 23, 2017 at 8:19 am

    Hi Sushant,

    You can get ID in the JS controller directly, no need to assign to another attribute,

    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.showCaseDelete}" id={!case.Id}>Delete</button>
    </aura:iteration>

    In your JS controller, capture the ID as as source of event:

    showCaseDelete: function(component, event, helper) {
    var idx = event.target.id;
    alert(idx); //here is your ID
    });

    Hope this helps you.

    Thanks

  • sushant

    Member
    January 23, 2017 at 9:58 am

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos

Salesforce Admin Certification 2020 Questions Explained with References - Part II

Video in

How to prepare and pass Salesforce Admin Certification with Practice Exam Questions 2020 practice questions and answers for the Salesforce Administration Salesforce Certified Admin Exam Questions Salesforce Administrator Certification Exam…