function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Marco SchmitMarco Schmit 

Lightning Components pass parameter to controller function

Hi,

I'm currenty trying to master this use case:
Lets say we have an object and on the page we have the option to delete this object. Now the delete button gets clicked and a bootstrap modal pops up asking if this object really should be deleted. By clicking yes the object gets deleted.

My problem is to remember this clicked object so I know which one has to be deleted by clicking the modal yes button. 
So in a nutshell ... how can I pass the object id to a component parameter when the delete button gets clicked?

Thank you!
Marco SchmitMarco Schmit
Somthing like this:
<aura:iteration items="{!v.newCases}" var="case">
<button type="button" onclick="{!c.showCaseDeleteModal(case.Id)}">Delete</button>
</aura:iteration>

 
Leo WangLeo Wang
@Marco Schmit, the code posted didn't work for me. are you sure?
<button type="button" onclick="{!c.showCaseDeleteModal(case.Id)}">Delete</button>
Balázs RubicsekBalázs Rubicsek
Good question! What is the proper way of passing parameters from component to controller function? The old visual force way does not work. 
desmoquattrodesmoquattro
Try this article guys:
https://developer.salesforce.com/blogs/developer-relations/2015/03/lightning-components.html

It covers passing parameters. The example provided looks like this:
loadContact : function(component) {
    var action = component.get("c.getContact");

    action.setParams({
        contactId : component.get("v.contactId")
    });

    action.setCallback(this, function(a) {
        if (a.getState() === "SUCCESS") {
            component.set("v.contact", a.getReturnValue());
        } else if (a.getState() === "ERROR") {
            $A.log("Errors", a.getError());
        }
    });

    $A.enqueueAction(action);
}


 
RohRoh
Hello Marco,
Why don't you try it like below?
 
<aura:iteration items="{!v.newCases}" var="case">
<button type="button" onclick="{!c.showCaseDeleteModal}" id={!case.Id}>Delete</button> </aura:iteration>
<aura:iteration items="{!v.newCases}" var="case">
<button type="button" onclick="{!c.showCaseDeleteModal}" id={!case.Id}>Delete</button> </aura:iteration>

https://developer.salesforce.com/forums/?id=906F0000000kAn0IAE

Please mark this as the right answer, if it solves your problem.

Thanks,
Rohit Alladi
 
harshal pawarharshal pawar

In Component

<div onclick="{!c.sendMessage}" data-value="{!contact.Phone}">
     <lightning:button label="Send Message" iconName="utility:send" iconPosition="left"  variant="brand" value="{!contact.Phone}"/>
  </div>

In controller

sendMessage: function(component, event, helper) {
    var ctarget = event.currentTarget; 
    var id_str = ctarget.dataset.value;
    console.log(id_str);
}

Thanks.