Component Code :
<aura:component controller="TestController" implements="forceCommunity:availableForAllPageTypes">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="country" type="Contact" default="{ sobjectType: 'Contact' }" />
<ui:inputSelect label = "country" aura:id="InputSelectDynamic">
<aura:iteration items="{!v.country.Country__c}" var="CountryName">
<ui:inputSelectOption text="{!CountryName}" label="{!CountryName}"/>
</aura:iteration>
</ui:inputSelect>
</aura : compomnent>
Controller Code
({
doInit: function(component, evt, helper) {
var action = component.get("c.getAccount");
action.setCallback(this, function(a) {
component.set("v.country", a.getReturnValue());
});
$A.enqueueAction(action);
},
})
Apex Controller
public class TestController{
@AuraEnabled
public static Account getAccount() {
return [select Country__c from Contact];
}
}
Question :
I am not getting any record in the drop down , can any one tell me what is wrong with the code.
my controller is having simple SQL select query and that is working fine.
Best Answer
To just display picklist country__c related to the contact on the UI
Approach 1 using force:inputfield
Component:
Controller:
Apex Class:
Renderer:
There is a bug with picklist when using force:inputField for which an workaround is provided here
Lightning Components: why force:inputField picklist select renders disabled?
Approach 2: populating pick list values dynamically through apex controller:
COPY PASTE THE EXACT CODE CHANGE THE FOLLOWING LINE IN THE APEX CLASS TO GET THE DESIRED PICKLIST
Component:
JS Controller:
Apex class: