You need to sign in to do that
Don't have an account?
supriya Gore
Trying to display list of records for custom object using lightning component but my code is not working properly
component:
<aura:component implements="force:appHostable" controller="FetchRegistrations" >
<aura:attribute name="reg" type="Registration__c[]"/>
<ui:button label="Get Registrations" press="{!c.myAction}"/>
<aura:iteration var="r" items="{!v.reg}" >
<p>{!r.name}</p>
</aura:iteration>
</aura:component>
Controller:
({
myAction : function(component, event, helper) {
var action = component.get("c.getAllregistrations");
action.setCallback(this, function(response){
var name = response.getState();
if (name === "SUCCESS") {
component.set("v.reg", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
Apex:
global with sharing class FetchRegistrations {
@auraEnabled
public static List<Registration__c> getAllregistrations()
{
List<Registration__c> reg=new LIST<Registration__c>();
reg=[select id,name,Email__c from Registration__c];
return reg;
}
public Registration__c getSelectedregistrations(Id id)
{
Registration__c reg=[select id,name,Email__c from Registration__c where id=:id];
return reg;
}
}
<aura:component implements="force:appHostable" controller="FetchRegistrations" >
<aura:attribute name="reg" type="Registration__c[]"/>
<ui:button label="Get Registrations" press="{!c.myAction}"/>
<aura:iteration var="r" items="{!v.reg}" >
<p>{!r.name}</p>
</aura:iteration>
</aura:component>
Controller:
({
myAction : function(component, event, helper) {
var action = component.get("c.getAllregistrations");
action.setCallback(this, function(response){
var name = response.getState();
if (name === "SUCCESS") {
component.set("v.reg", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
Apex:
global with sharing class FetchRegistrations {
@auraEnabled
public static List<Registration__c> getAllregistrations()
{
List<Registration__c> reg=new LIST<Registration__c>();
reg=[select id,name,Email__c from Registration__c];
return reg;
}
public Registration__c getSelectedregistrations(Id id)
{
Registration__c reg=[select id,name,Email__c from Registration__c where id=:id];
return reg;
}
}
All Answers
After clicking button,i am getting blank page.
Yeeeeh its working...!Thanks
I want to show more fields ex: {!r.name....Id....billingcity}
How to do?