You need to sign in to do that
Don't have an account?
shubham soitkar 6
Lightning buttton onclick not executing, could someone please help me
controller:-
({
doInit : function(component, event, helper) {
// create a one-time use instance of the serverEcho action
// in the server-side controller
var action = component.get("c.getcontact");
action.setParams({ accountId : component.get('v.recordId'), });
// Create a callback that is executed after
// the server-side action returns
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
// Alert the user with the value returned
// from the server
component.set("v.contactname",response.getReturnValue());
console.log(response.getReturnValue());
// You would typically fire a event here to trigger
// client-side notification that the server-side
// action is complete
}
else if (state === "INCOMPLETE") {
// do something
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
// optionally set storable, abortable, background flag here
// A client-side action could cause multiple events,
// which could trigger other events and
// other server-side action calls.
// $A.enqueueAction adds the server-side action to the queue.
$A.enqueueAction(action);
},
doButton : function(component, event, helper) {
var eventSource = event.getSource();
var id = eventSource.get(v.name);
alert(id);
}
});
Aura Component:
<aura:component controller="contactclass" implements="flexipage:availableForAllPageTypes,force:hasRecordId">
<aura:attribute name="contactname" type="Contact[]" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
{!v.recordId}
<div class="slds-grid slds-wrap">
<aura:iteration items="{!v.contactname}" var="item" >
<div class="slds-col slds-size_1-of-3">
<div class="slds-p-around_x-small">
<lightning:card footer="Business Card" title="Cognizant" variant="Narrow" iconName="standard:employee_asset">
<aura:set attribute="actions">
<lightning:button variant="brand" name="values" label="More" title="Brand action" onclick="{!c.doButton }" />
</aura:set>
<p class="slds-p-horizontal_small">
{!item.FirstName} {!item.LastName}<br />
</p>
</lightning:card>
</div>
</div>
</aura:iteration>
</div>
</aura:component>
contact class:-
({
doInit : function(component, event, helper) {
// create a one-time use instance of the serverEcho action
// in the server-side controller
var action = component.get("c.getcontact");
action.setParams({ accountId : component.get('v.recordId'), });
// Create a callback that is executed after
// the server-side action returns
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
// Alert the user with the value returned
// from the server
component.set("v.contactname",response.getReturnValue());
console.log(response.getReturnValue());
// You would typically fire a event here to trigger
// client-side notification that the server-side
// action is complete
}
else if (state === "INCOMPLETE") {
// do something
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
// optionally set storable, abortable, background flag here
// A client-side action could cause multiple events,
// which could trigger other events and
// other server-side action calls.
// $A.enqueueAction adds the server-side action to the queue.
$A.enqueueAction(action);
},
doButton : function(component, event, helper) {
var eventSource = event.getSource();
var id = eventSource.get(v.name);
alert(id);
}
});
Aura Component:
<aura:component controller="contactclass" implements="flexipage:availableForAllPageTypes,force:hasRecordId">
<aura:attribute name="contactname" type="Contact[]" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
{!v.recordId}
<div class="slds-grid slds-wrap">
<aura:iteration items="{!v.contactname}" var="item" >
<div class="slds-col slds-size_1-of-3">
<div class="slds-p-around_x-small">
<lightning:card footer="Business Card" title="Cognizant" variant="Narrow" iconName="standard:employee_asset">
<aura:set attribute="actions">
<lightning:button variant="brand" name="values" label="More" title="Brand action" onclick="{!c.doButton }" />
</aura:set>
<p class="slds-p-horizontal_small">
{!item.FirstName} {!item.LastName}<br />
</p>
</lightning:card>
</div>
</div>
</aura:iteration>
</div>
</aura:component>
contact class:-
Try below line
var id = eventSource.get("v.name");
Thanks
All Answers
replace following method. you forgot to put v.name into string.
It must be in 'v.name'.
let me know if it helps you and don't forget to marking it as best.
Thank you
Try below line
var id = eventSource.get("v.name");
Thanks