public class PersonController {
@AuraEnabled public String Name {get;set;}
@AuraEnabled public integer Age {get;set;}
@auraEnabled public List<Account> ListOfAccounts {get;set;}
@AuraEnabled
public static PersonController initMethod(){
PersonController person = new PersonController();
person.Name = 'John Doe';
person.Age = 30 ;
person.ListOfAccounts = [SELECT Id, Name FROM Account LIMIT 10];
return person ;
}
}
Note the attribute
personController
of type PersonController
.<aura:component controller="PersonController">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="personController" type="PersonController"/>
<div>
Name: {!v.personController.Name}<br />
Age: {!v.personController.Age}<br />
</div>
<div>
List of Accounts:
<aura:iteration items="{!v.personController.ListOfAccounts}" var="account">
<li>{!account.Name}</li>
</aura:iteration>
</div>
</aura:component>
({
doInit : function(component, event, helper) {
var action = component.get('c.initMethod');
action.setCallback(this,function(response){
var state = response.getState();
if (state === "SUCCESS") {
component.set('v.personController', response.getReturnValue());
}
});
$A.enqueueAction(action);
},
})
0 comments:
Post a Comment