function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LUIGI EMANUEL TAORMINALUIGI EMANUEL TAORMINA 

how to invoke this method in aura component?

Hi, this method gives me a map. I would like to call this method in aura component and haveit displayed on the screen .

User-added image
Best Answer chosen by LUIGI EMANUEL TAORMINA
mukesh guptamukesh gupta
Hi LUIGI,

Please use below code:-
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
<aura:handler name="init" value ={!this} action="{!c.doinit}"/>
<aura:attribute name="product" type="List" />
<aura:iteration items="{!v.product}" var="prod" indexVar="key">
{!prod.key} – {!prod.value}<br/><br/>
</aura:iteration>
</aura:component>
({
 doinit : function(component, event, helper) {  
	var action = component.get("c.getMap");
	action.setCallback(this, function(response) {
	var state = response.getState();
	if (state === "SUCCESS") {
	var custs = [];
	var conts = response.getReturnValue();
	for ( var key in conts ) {
	custs.push({value:conts[key], key:key});
	}
	component.set("v.product", custs);
	}
	});
	$A.enqueueAction(action);
}
})

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

 

All Answers

Balaji Selva Sekaran 8Balaji Selva Sekaran 8
In the js file you can call the apex method using the below piece of code.

var action = component.get("c.getMap"); // calling the server side action using c notifier
LUIGI EMANUEL TAORMINALUIGI EMANUEL TAORMINA
how do i displaythe map records in the component ?
 
mukesh guptamukesh gupta
Hi LUIGI,

Please use below code:-
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
<aura:handler name="init" value ={!this} action="{!c.doinit}"/>
<aura:attribute name="product" type="List" />
<aura:iteration items="{!v.product}" var="prod" indexVar="key">
{!prod.key} – {!prod.value}<br/><br/>
</aura:iteration>
</aura:component>
({
 doinit : function(component, event, helper) {  
	var action = component.get("c.getMap");
	action.setCallback(this, function(response) {
	var state = response.getState();
	if (state === "SUCCESS") {
	var custs = [];
	var conts = response.getReturnValue();
	for ( var key in conts ) {
	custs.push({value:conts[key], key:key});
	}
	component.set("v.product", custs);
	}
	});
	$A.enqueueAction(action);
}
})

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

 
This was selected as the best answer
mukesh guptamukesh gupta
Hi LUIGI,

If my solution is helpful for you then please

Kindly mark my solution as the best answer.

Thanks
Mukesh