You need to sign in to do that
Don't have an account?
pankaj singla 39
Trailhead Lightning Component Framework Specialist Step 6 - Getting Attribute name issue
Hi,
I am facing issue with Step 6. I am able to pass the chalenge but the functionality is not working. The error is I am not able to get the Id of the selected boat in the BoatTileController. PFB my Code
#Parent Component- BoatSearchResults.cmp
#Child Component: BoatTile.cmp
Controller: BoatTileController
I need to get the attribute boat in the BoatTileController but it shows the value as Undefined. Please help me resolve the issue.
I am facing issue with Step 6. I am able to pass the chalenge but the functionality is not working. The error is I am not able to get the Id of the selected boat in the BoatTileController. PFB my Code
#Parent Component- BoatSearchResults.cmp
<aura:component controller="BoatSearchResults"> <aura:method name="search" action="{!c.search}" description="Sample method with parameters" access="public"> <aura:attribute name="param1" type="String"/> </aura:method> <aura:attribute name="boats" type="Boat__c[]" /> <aura:attribute name="boatTypeId" type="string" default="" /> <aura:attribute name="selectedBoatId" type="Id" default="" /> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <aura:handler name="BoatSelect" event="c:BoatSelect" action="{!c.onBoatSelect}"/> <lightning:layout multipleRows="true" horizontalAlign="center"> <aura:iteration items="{!v.boats}" var="boatVar"> <lightning:layoutItem flexibility="grow" class="slds-m-right_small" > <c:BoatTile boat="{!boatVar}" selected="{!boatVar.Id == v.selectedBoatId ? 'true' : 'false' }"/> </lightning:layoutItem> </aura:iteration> <aura:if isTrue="{!v.boats.length==0}"> <lightning:layoutItem class="slds-align_absolute-center" flexibility="auto" padding="around-small"> <ui:outputText value="No boats found" /> </lightning:layoutItem> </aura:if> </lightning:layout> </aura:component>
#Child Component: BoatTile.cmp
<aura:component > <aura:attribute name="boat" type="Boat__c" /> <aura:attribute name="selected" type="boolean" default="false"/> <aura:registerEvent name="BoatSelect" type="c:BoatSelect"/> <aura:attribute name="selectedBoatId" type="Id"/> <lightning:button label="Packed!" onclick="{!c.onBoatClick}" class="{! v.selected ? 'tile selected' : 'tile' }"> <div style="{!'background-image:url(\'' + v.boat.Picture__c + '\')'}" class="innertile"> <div class="lower-third"> <h1 class="slds-truncate">{! v.boat.Contact__r.Name}</h1> </div> </div> </lightning:button> </aura:component>
Controller: BoatTileController
({ onBoatClick : function(component, event, helper) { var cmpEvent = component.getEvent("BoatSelect"); //var boatId = component.get("v.boat.Id"); var bb=component.get("v.boat"); console.log('var bb is-'+bb.id); var boatId = event.getSource().get("v.label"); console.log('boatId-'+boatId); cmpEvent.setParams({ "boatId" : boatId }); cmpEvent.fire(); } })
I need to get the attribute boat in the BoatTileController but it shows the value as Undefined. Please help me resolve the issue.
For your issue in component please try the below code:
Please make it best if it helps you.
Thanks,
Ajay
Thanks for quick response. I have tried the code but no success.
Regards,
Pankaj