0

I have a cmp with List of objects and iteration:

<aura:iteration items="{!v.Objects}" var="object">
    <div label="Set Id" name="{!object.Id}" onclick="{!c.action}">
        {!object.Name}
    </div>
</aura:iteration>

Now by clicking "Set Id" I need to set the Id of that concrete object to my event. Now I set and get [event.getSource is not a function]:

var cmpEvt = component.getEvent("cmpEvt");
var objId =  event.getSource().get("v.name");
cmpEvt.setParams({"id" : "object.Id"});
cmpEvt.fire();

How can I fix it?

1 Answer 1

1

cmp

 <div label="Set Id" data-record="{!object.Id}" onclick="{!c.action}">
    {!object.Name}
</div>

controller.js

  action : function(cmp,evt){
   var objId =  evt.currentTarget.dataset.record;
    var cmpEvt = cmp.getEvent("cmpEvt");
    cmpEvt.setParams({"id" : objId });
    cmpEvt.fire();
    }
6
  • Thank you. But... Hmm. [event.getSource is not a function] Can it be because of list and iteration? Commented Jun 26, 2019 at 14:37
  • can you updated your question with actual error code? so that it's easy to reproduce the issue
    – sdandamud1
    Commented Jun 26, 2019 at 16:06
  • 1
    Please upvote if solution works for you for help others
    – sdandamud1
    Commented Jun 26, 2019 at 17:02
  • Sorry for the misinformation. I recently changed the button to div. Everything works with the button, but not with div. Commented Jun 26, 2019 at 17:04
  • for div you have to use datasets , edited my answer based on your comments.
    – sdandamud1
    Commented Jun 26, 2019 at 17:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .