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
Sagar SirsatSagar Sirsat 

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
Best Answer chosen by Sagar Sirsat
David Zhu 🔥David Zhu 🔥
You may change to the following and check the value?
 component.set("v.beerId" , beer);
var a = component.get("v.beerId");

All Answers

David Zhu 🔥David Zhu 🔥
You may change to the following and check the value?
 component.set("v.beerId" , beer);
var a = component.get("v.beerId");
This was selected as the best answer
Sagar SirsatSagar Sirsat
Thanks David , It worked!!