Hello Shubham ,
you can try this :
server-side Controller :
public class SearchAcc {
@AuraEnabled
public static List<Account> getAccList(){
List<Account> acct=[select name,AccountNumber,phone,Description from account Limit 100];
return acct;
}
@AuraEnabled
public static Account getAcc(String ID){
return[select name,Phone,Description from account where id= :ID];
}
}
Component :
<aura:component controller=”SearchAcc” >
<aura:registerEvent name=”AccEvent” type=”c:AccountDetailsEvent”/>
<aura:attribute name=”Accounts” type=”Account[]”/>
<aura:handler name=”init” value=”{!this}” action=”{!c.getList}”/>
<aura:iteration items=”{!v.Accounts}” var=”acc”>
<h1><a id=”{!acc.Id}” title=”click me to do something” href=”#” onclick=”{!c.getID}” >
{!acc.Name}</a>
</h1>
</aura:iteration>
</aura:component>
client-side controller :
({
getList : function(component, event, helper) {
var action = component.get(“c.getAccList”);
action.setCallback(this,function(response){
var state = response.getState();
if(state == “SUCCESS”){
alert(‘success’)
component.set(“v.Accounts”,response.getReturnValue());
}
});
$A.enqueueAction(action);
},
getID: function(component, event, helper) {
var Ide = event.srcElement.id;
var action= component.get(“c.getAcc”);
action.setParams({ ID :Ide });
action.setCallback(this, function(response) {
var state = response.getState();
if (state === “SUCCESS”) {
// console.log(response.getReturnValue());
}
var Eve=component.getEvent(“AccEvent”);
Eve.setParams({ “Reqdata” :response.getReturnValue()});
console.log(Eve.getParam(“Reqdata”))
Eve.fire();
});
$A.enqueueAction(action);
}
})
-
This reply was modified 8 years, 8 months ago by
Aman.