I've got an aura iteration that looks like this:
<aura:component description="ResourceTiles" implements="forceCommunity:searchInterface" controller="MainBrowser">
<aura:attribute name="resources" type="Resource__c[]" access="public" />
<aura:attribute name="resource" type="Resource__c" access="public" default="{'sobjectType': 'Resource__c', 'Name': 'Volvo XC90', 'Comment__c': ''}"/>
<aura:attribute name="selectedResourceId" type="Id" access="public" />
<aura:registerEvent name="ResourceSelected" type="c:ResourceSelected" />
<div class="slds-scrollable--x">
<table class="slds-table slds-table--bordered slds-table--cell-buffer slds-table--striped">
<thead>
<tr class="slds-text-title_caps">
<th scope="col"><div class="slds-truncate" title="Car Selection"></div></th>
<th scope="col"><div class="slds-truncate" title="Model">Car Model</div></th>
<th scope="col"><div class="slds-truncate" title="Engine Information">Engine</div></th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.resources}" var="resource">
<tr>
<td>
<lightning:button label="{!resource.Id}" aura:id="allButtons" onclick="{!c.changeColor}" value="{resource.Id}">
</lightning:button>
</td>
<td>
<div class="slds-truncate" title="{!resource.Name}">
{!resource.Name}
</div>
</td>
<td>
<div class="slds-truncate" title="{!resource.Comment__c}">
{!resource.Comment__c}
</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
and a Controller that looks like this:
changeColor: function(component, event, helper) {
var resource = event.getSource().get("v.value");
var event = component.getEvent("ResourceSelected");
event.setParams({
resourceId: resource.Id
});
event.fire();
Why am I receiving undefined for the resource Id? The label on the button itself is successfully displaying the record ID. I'm just having issues passing it to my controller - what am I missing here?
resource
in youraura:attribute
andaura:iteration
. Try changing one of them?value
of the button to the resource's Id, but you're then takingv.value.Id
within your event handler. Type mismatch?