I want to display records from custom object based on SOQL query from Apex class. I have referred to this Article which explains how to do that. However I am not able to display records on the component. The following shows the code:
Apex Class:
public with sharing class Olympic {
@AuraEnabled
public static List<Olympic_Rewards__c> Olympic(){
return [SELECT Id, Name, StatusBar__c,Reward_level__c,Agency_Name__c,Agency__c from Olympic_Rewards__c];
}
}
Component:
<aura:component controller="Olympic" implements="forceCommunity:availableForAllPageTypes" access="global">
<aura:attribute name="OlympicReward" type="Olympic_Rewards__c[]"/>
<!-- <ui:button label="Check Reward status" press="{!c.getMyObjects}" /> -->
<aura:iteration var="OLRS" items="{!v.OlympicReward}">
<p>{!OLRS.Name},
{!OLRS.StatusBar__c}</p>
</aura:iteration>
Component Controller:
({
getMyObjects: function(cmp){
var action = cmp.get("c.Olympic");
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
cmp.set("v.myObjects", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
Can someone please help me identify the problem? Above code doesn't display anything while previewing App? No errors.