+ Start a Discussion
Kishore Vamsi 6Kishore Vamsi 6 

How to populate list of strings in select pick list in lightning

I am getting list if string from apex and I want display those strings into one selected picklist and finally user can select one string in that picklist.
 
Apex Returns List<string>  s = [{"Banglore","Chennai","Noida"}];

At the end user able to select any one of city in selected picklist
Best Answer chosen by Kishore Vamsi 6
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Try like this.Kindly Modify it according to your apex controller method
<aura:component controller= "picklistvaluesController"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" 
                access="global" >

	    <aura:attribute name="picklistvalues" type="string[]" />
            <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<lightning:select aura:id="PicklistId" label="Enter Last Class Percentage" name="percent" >
			<option value="" text="- None -" /> 
            <aura:iteration items="{!v.picklistvalues}" var="pickval">
            	<option value="{!pickval}" text="{!pickval}" />  
        	</aura:iteration>
    	</lightning:select>
</aura:component>

js controller

({
    doInit : function(component, event, helper) {
        var action = component.get("c.getPicklistvalues");
        action.setCallback(this, function(response) {
            var Values = response.getReturnValue();
            component.set("v.picklistvalues", values);

        });
        $A.enqueueAction(action); 
        
    }
})

Please refer below link which might help you in this
https://developer.salesforce.com/forums/?id=9060G0000005pEeQAI 

Hope this helps you
Let me know if this helps you by marking it as solved so that it may help others in future.

Thanks and Regards

All Answers

Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Try like this.Kindly Modify it according to your apex controller method
<aura:component controller= "picklistvaluesController"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" 
                access="global" >

	    <aura:attribute name="picklistvalues" type="string[]" />
            <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<lightning:select aura:id="PicklistId" label="Enter Last Class Percentage" name="percent" >
			<option value="" text="- None -" /> 
            <aura:iteration items="{!v.picklistvalues}" var="pickval">
            	<option value="{!pickval}" text="{!pickval}" />  
        	</aura:iteration>
    	</lightning:select>
</aura:component>

js controller

({
    doInit : function(component, event, helper) {
        var action = component.get("c.getPicklistvalues");
        action.setCallback(this, function(response) {
            var Values = response.getReturnValue();
            component.set("v.picklistvalues", values);

        });
        $A.enqueueAction(action); 
        
    }
})

Please refer below link which might help you in this
https://developer.salesforce.com/forums/?id=9060G0000005pEeQAI 

Hope this helps you
Let me know if this helps you by marking it as solved so that it may help others in future.

Thanks and Regards
This was selected as the best answer
Kishore Vamsi 6Kishore Vamsi 6
Wow Awesome. It is working for me.

Thanks Devi, for Quick reponse.