You need to sign in to do that
Don't have an account?

Unable to set Id in attribute in Lightning Component
COMPONENT
---------------------
<aura:component >
<aura:attribute name="recordList" type="object" />
<aura:attribute name="beerId" type="string"/>
<div class="slds-p-arround_small" style="background-color: powderblue;" >
<div class="slds-grid slds-wrap">
<aura:iteration items="{!v.recordList}" var="item">
<div class="slds-col slds-size_1-of-4 slds-p-around_small" >
<lightning:card title="{!item.Name}" footer="{!item.Brewery_Name__c}"
iconName="custom:custom7" >
<p class="slds-p-horizontal_small">
<div class="slds-grid slds-gutters">
<div class="slds-col slds-size_1-of-3">
<img src="{!$Resource.beer}" />
</div>
<div class="slds-col slds-size_2-of-3">
Name: {!item.Name} <br/>
Id : {!item.Id__c} <br/>
Alcohol% : {!item.Alcohol__c} <br/>
</div>
</div>
</p>
<aura:set attribute="actions" >
<lightning:button name="{!item.Id}" label="View Detail" variant="brand" onclick="{!c.showInfo}"/>
</aura:set>
</lightning:card>
</div>
</aura:iteration>
</div>
<c:beerDetails />
</div>
</aura:component>
CONTROLLER
---------------------
({
showInfo : function(component, event, helper) {
var a = event.getSource();
var beer = a.get('v.name');
var a = component.set("v.beerId" , beer);
alert(a);
}
})
*ALERT SHOWS UNDEFINED
---------------------
<aura:component >
<aura:attribute name="recordList" type="object" />
<aura:attribute name="beerId" type="string"/>
<div class="slds-p-arround_small" style="background-color: powderblue;" >
<div class="slds-grid slds-wrap">
<aura:iteration items="{!v.recordList}" var="item">
<div class="slds-col slds-size_1-of-4 slds-p-around_small" >
<lightning:card title="{!item.Name}" footer="{!item.Brewery_Name__c}"
iconName="custom:custom7" >
<p class="slds-p-horizontal_small">
<div class="slds-grid slds-gutters">
<div class="slds-col slds-size_1-of-3">
<img src="{!$Resource.beer}" />
</div>
<div class="slds-col slds-size_2-of-3">
Name: {!item.Name} <br/>
Id : {!item.Id__c} <br/>
Alcohol% : {!item.Alcohol__c} <br/>
</div>
</div>
</p>
<aura:set attribute="actions" >
<lightning:button name="{!item.Id}" label="View Detail" variant="brand" onclick="{!c.showInfo}"/>
</aura:set>
</lightning:card>
</div>
</aura:iteration>
</div>
<c:beerDetails />
</div>
</aura:component>
CONTROLLER
---------------------
({
showInfo : function(component, event, helper) {
var a = event.getSource();
var beer = a.get('v.name');
var a = component.set("v.beerId" , beer);
alert(a);
}
})
*ALERT SHOWS UNDEFINED
component.set("v.beerId" , beer);
var a = component.get("v.beerId");
All Answers
component.set("v.beerId" , beer);
var a = component.get("v.beerId");