+ Start a Discussion
Manish Anand 22Manish Anand 22 

lightning component framework SuperBadge challenge 3

Hi,
I passed this challenge. However, when I load the it, (through lightning page or an app) it gives an error- Action failed: c:BoatSearchResults$controller$doSearch [component is not defined]
In the code as well, there seems to be no reason to get this error. Below is my code.
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" 
                access="global" controller="BoatSearchResults">
    <aura:handler name="init"  value="{!this}" action="{!c.doSearch}" /> 
	<aura:attribute name="boats" type="Boat__c[]" />

    <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}"/>
                </lightning:layoutItem>
            </aura:iteration>
    		
               
            <aura:if isTrue="{!lessthan(v.boats.length,1)}">
                <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>
 
({
	doSearch: function(component, event, helper) {
        console.log('In do Search');
		helper.onSearch(component,event,helper);
	}
});
 
({
	onSearch : function(Component, event, helper) {
        console.log('In Helper');
		var action=component.get('c.getBoats');
        action.setCallback(this,function(response) {
            if(response.getState === 'SUCCESS')
            {
                var boatslist = response.getReturnValue();
                component.set("v.boats",boatslist);
            }
        });
        $A.enqueueAction(action);
	}
})
Below is the screenshot of the error message:
User-added image

Any hints, why it wouldn't load the app?

Thanks,
Manish
Raj VakatiRaj Vakati
Java script is case sensitive .. "Component" should be component . Here is the code

 
({
	onSearch : function(component, event, helper) {
        console.log('In Helper');
		var action=component.get('c.getBoats');
        action.setCallback(this,function(response) {
            if(response.getState === 'SUCCESS')
            {
                var boatslist = response.getReturnValue();
                component.set("v.boats",boatslist);
            }
        });
        $A.enqueueAction(action);
	}
})

 
Raj VakatiRaj Vakati
You are using "Component"  C In the capital letter. it should be component
Manish Anand 22Manish Anand 22
Thanks Raj. However, when I reload the page now, it shows 'No boats found'. Shouldn't it display all the boats during reload (Since 'All types' is selected). Below is my helper and apex.
 
({
	onSearch : function(component, event, helper) {
        console.log('In Helper');
		var action=component.get('c.getBoats');
         action.setParam({"boatTypeId":''});
        action.setCallback(this,function(response) {
            if(response.getState === 'SUCCESS')
            {
                var boatslist = response.getReturnValue();
                component.set("v.boats",boatslist);
            }
        });
        $A.enqueueAction(action);
	}
})
 
public with sharing class BoatSearchResults {

    @Auraenabled
    public static List<Boat__c> getBoats(String boatTypeId)
    {
       if(boatTypeId != '')
       {
       return ([Select Id,Name, BoatType__c , Contact__r.Name , Description__c,Geolocation__c,Length__c,Price__c,Year_Built__c
               from Boat__c Where Id = :boatTypeId]); 
       }
       else
       {
           return ([SELECT Id, BoatType__c, picture__c, name,contact__r.Name from Boat__c]);
       }
    }
}

Thanks,
Mohammad Shahid ShahMohammad Shahid Shah

Challenge Not yet complete... here's what's wrong:
The getBoats() method isn't working properly. Define getBoats() In the BoatSearchResults Apex controller to accept an optional boatTypeId and return all boats if no boatTypeId is passed, and a filtered list of boats if a boatTypeId is passed.
Close errors :  Can someone help me out !