Created
February 20, 2019 19:18
-
-
Save choudharymanish8585/838eac238653a24eb2576644408b6f57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component implements="force:appHostable" extends="c:Base" controller="CarSearchController"> | |
<aura:attribute type="Car__c[]" name="cars" access="public" /> | |
<aura:attribute type="String" name="carTypeId" access="private" default="" /> | |
<aura:attribute type="boolean" name="carFound" access="private" default="false" /> | |
<aura:attribute type="Id" name="selectedCarId" access="public"/> | |
<aura:handler name="init" action="{!c.doInit}" value="{!this}" /> | |
<!-- this event is being fired by nested CarTile component | |
when user clicks on any car, will handle this event here | |
to mark the car as selected --> | |
<aura:handler name="onCarSelect" event="c:CarSelect" action="{!c.onCarSelect}" /> | |
<!-- This aura method will be invoked by parent component CarSearch | |
and will pass carTypeId, the method will use carTypeId to seacrh | |
all the cars from server with having same carTypeId --> | |
<aura:method name="searchCars" action="{!c.doSearch}" | |
description="Get cars from server based on carTypeId supplied | |
to this component" access="public"> | |
<aura:attribute name="carTypeId" type="String" default="" /> | |
</aura:method> | |
<lightning:layout multipleRows="true" horizontalAlign="center"> | |
<aura:if isTrue="{!v.carFound}"> | |
<aura:iteration items="{!v.cars}" var="car"> | |
<lightning:layoutItem padding="around-small" size="12" | |
smallDeviceSize="6" | |
mediumDeviceSize="4" | |
largeDeviceSize="3"> | |
<!-- Calling CarTile component in loop to display all car result --> | |
<c:CarTile car="{#car}" selected="{!v.selectedCarId == car.Id ? true : false}" /> | |
</lightning:layoutItem> | |
</aura:iteration> | |
<!-- This is the else part of aura:if, if no car result found, | |
it will show a simple message --> | |
<aura:set attribute="else"> | |
<div class="slds-align_absolute-center"> | |
No cars found | |
</div> | |
</aura:set> | |
</aura:if> | |
</lightning:layout> | |
</aura:component> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment