You need to sign in to do that
Don't have an account?
Mike O.
Dynamically selected value in a list
The selected value in a list is not set as expected. The code in the .js controller is:
In the component I have:
I used a time delay between creating the list and setting the selected value in the list and it seems to do the trick.
Is there another more elegant way of fixing this issue?
setListLocations : function(cmp, response) { var list = response.getReturnValue().Locations; var locations = []; for (var i=0; i< list.length; i++) { var loc = {value: list[i], label: list[i]}; locations.push(loc); } cmp.set("v.locations", locations); cmp.set("v.selectedValue", response.getReturnValue().Location); },From what I have been reading the value is not set as the list is not ready at that time.
In the component I have:
<lightning:select name="mySelect" onchange="{!c.getValue }" label="To" aura:id="mySelect" value="{!v.selectedValue}" > <aura:iteration items="{!v.locations}" var="item"> <option value="{!item.value}" selected="{!item.selected}"> {!item.label} </option> </aura:iteration> </lightning:select>From what I have been reading the value is not set as the list is not ready at that time.
I used a time delay between creating the list and setting the selected value in the list and it seems to do the trick.
window.setTimeout( $A.getCallback(function() { cmp.set("v.selectedValue", response.getReturnValue().Location); }), 75 );However, I'm not quite happy with this solution.
Is there another more elegant way of fixing this issue?