• Tanmaya Samal 5
  • NEWBIE
  • 0 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi everyone, I am working on a Lightning Component which has a lightning select with its values fetched dynamically from a picklist field.
 
<lightning:select aura:id="select" label="Estado de la cita" name="source" onchange="{!c.handleSelect}" class="slds-m-bottom_medium">
     <option value="" disabled="true" text="-- Selecciona Estado --"/>
     <option value="Todos" text="Todos"/>
     <aura:iteration var="stat" items="{!v.statusList}">
          <option value="{!stat}" text="{!stat}"/>
     </aura:iteration>
 </lightning:select>

I found on the Internet this solution but it's not working for me
doInit: function(cmp){
        
        var action = cmp.get("c.getStatus");
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            var statusList = response.getReturnValue();
            if(state == "SUCCESS"){
                cmp.set("v.statusList",statusList);
                window.setTimeout(
                $A.getCallback( function() {
                    cmp.find("select").set("v.statusList", statusList[1]);
                }));
            }
        });
        
        $A.enqueueAction(action);
    },
The cmp.find recover the value I want but then that value it's not setted as default.

Someone can help me?

Regards and thanks in advance