0

I have apex controller that returns Map<String, List<sObject>>. I want to iterate through keys and through sObjects inside of parent iteration.

Apex:

@AuraEnabled
public static Map<String, List<sObject>> returnSObjectMap() {...}

Lightning Controller:

getsobjectMap : function(component) {
var action = component.get("c.returnSObjectMap");
action.setCallback(this, function(a) {
    if (a.getState() === "SUCCESS") {
        var sobjectFields = a.getReturnValue();
        var sobjectFieldsFinal = [];
        for (var key in sobjectFields) {
            sobjectFieldsFinal.push({value:sobjectFields[key], key:key});
        }               
        component.set('v.sobjectsMap',sobjectFieldsFinal);
    } else if (a.getState() === "ERROR") {

    }
});

$A.enqueueAction(action);}

Component:

...
<aura:attribute name="sobjectsMap" type="List"/>
...
<aura:iteration items="{! v.sobjectsMap }" var="sobjectList" indexVar="key">
    <apex:iteration items="{! sobjectList }" var="sobject">
    ...
    </apex:iteration>
</aura:iteration>

I'm receiving an error when trying so save on line:

<apex:iteration items="{! sobjectList }" var="sobject">

Error: No COMPONENT named markup://apex:iteration found

How can I iterate over inner list?

1

1 Answer 1

5

You misspelled it. It's aura:iteration instead of apex:iteration

<aura:iteration items="{! v.sobjectsMap }" var="sobjectList" indexVar="key">
    <aura:iteration items="{! sobjectList }" var="sobject">
    ...
    </aura:iteration>
</aura:iteration>
6
  • you added the same "iteration" Commented Nov 20, 2017 at 15:17
  • no, you are using apex I'm using aura
    – itsmebasti
    Commented Nov 20, 2017 at 15:18
  • sobjectsMap – is not a map. It's list as you can see in component. Commented Nov 20, 2017 at 15:18
  • 1
    if so, aura:iteration will fix it.
    – itsmebasti
    Commented Nov 20, 2017 at 15:20
  • lol, thank you! How can I missed that... Saved now :) But for some reason I can't display values like: {! sobject.Name } Commented Nov 20, 2017 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .