Dynamic Lightning Select With Dynamic Amount of Options

992    Asked by bhagwatidubey in Power BI , Asked on Jul 1, 2021

I'm looking to have a dynamic input that can be either a Dynamic PickList OR A Dynamic Input such as text or DateTime. $A.createComponent(String type, Object attributes, function callback) I have been using the above to great effect with lightning input. However, when I try to do the same with lightning select, all of the guidance says that I can't have a dynamic amount of options as it seems each option has to be hardcoded like below!

$A.createComponent( "lightning:select", [ [ "aura:id": "input", "label": cmp.get("v.label"), "onchange": cmp.getReference("c.onChange") ], [ "option", { value: "Option 1", label: "Option 1" } ], [ "option", { value: "Option 2", label: "Option 2" } ] ], function(icmp, status, errorMessage) { if (status === "SUCCESS") { var body = cmp.get("v.body"); body.push(icmp); cmp.set("v.body", body); } else if (status === "INCOMPLETE") { console.log("No response from server or client is offline.") } else if (status === "ERROR") { console.log("Error: " + errorMessage); } } );

Now I know I can set the value/label of each dynamically, but I cannot seem to have a dynamic number of options matching the length of a list, for example.


Answered by Celina Lagunas

from what I understand you want to bind options to variables, you can solve lightning:select error by using component.setReference. From what I remember it'll work like this icmp.setReference('v.options',cmp.getReference('v.myDynamicOptions'))



Your Answer

Interviews

Parent Categories