3

This question is similar: How to set the options of a dynamically created lightning:select?

but none of the solutions nest the iteration component inside another component..

like so:

Inside Controller:

someFunction(cmp, event, helper) : {
    $A.createComponents([
            [
                "lightning:select", { 
                    "aura:id":"selectPicklist",
                    "name":"selectPicklist",
                    "label":"Value",
                    "required":"true",
                    "messageWhenValueMissing":"Did you forget to select a field?",
                    "value":"-- None --"
                    }
            ],
            [
                "aura:iteration", {
                    "items":"{!v.picklistValues}",
                    "var":"picklistValue",
                    "value":"{!picklistValue}",
                    "text":"{!picklistValue}"
            }]
        ],
        function(components, status, errorMessage){
            if (status==="SUCCESS"){
                var selectCmp = components[0];
                var iterationCmp = components[1];
                selectCmp.set("v.body", iterationCmp);
                cmp.set("v.inputValueComponent", selectCmp);
                console.log(cmp.get("v.inputValueComponent").get("v.picklistValues"));
            }
            else if (status==="INCOMPLETE"){
                console.log("No response from server or client is offline.");
            }
                else if (status==="ERROR"){
                    console.log("Error: " + errorMessage);        
                }
        }                    

       );    
}

Inside Component

<aura:attribute name="inputValueComponent" type="Aura.Component">

<aura:attribute name="picklistValues" type="String[]" default="one, two, three"/>
2
  • and what seems to be the problem you are facing, errors if any?
    – glls
    Feb 13, 2018 at 21:42
  • adding to @glls comment - please share also the whole markup Feb 14, 2018 at 8:07

1 Answer 1

0
function (pill) {
   var body= component.get("v.body");
   body.push(pill);
   component.set("v.body", body);
}

You might have to use push to create components in iteration like above.

You must log in to answer this question.

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