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?

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>
  • you added the same "iteration" – Eugene Vabishchevich Nov 20 '17 at 15:17
  • no, you are using apex I'm using aura – Basti Nov 20 '17 at 15:18
  • sobjectsMap – is not a map. It's list as you can see in component. – Eugene Vabishchevich Nov 20 '17 at 15:18
  • 1
    if so, aura:iteration will fix it. – Basti Nov 20 '17 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 } – Eugene Vabishchevich Nov 20 '17 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.