You need to sign in to do that
Don't have an account?
Nithya S 1
Dynamic pick list
Hi, I'm trying to fetch picklist from a custom object but the value isn't being displayed. Get a blank dropdown. Please let me know what is missing..
Snippet Component :
<aura:attribute name="Location" type="Loc__c" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<lightning:select name="Location" aura:id="Location">
<aura:iteration items="{!v.Location}" var="loc">
<option value="{!v.loc.Loc__c}">
</option>
</aura:iteration>
Controller :
({
doInit: function(component,event,helper){
var action = component.get("c.getLocation");
action.setCallback(this, function(a){
component.set("v.Location",a.getReturnValue());
});
$A.enqueueAction(action)
},
Class:
public class LocSearchController {
@AuraEnabled
public static List<Location__c> getLocation(){
return [select Loc__c from Location__c];
}
}
Snippet Component :
<aura:attribute name="Location" type="Loc__c" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<lightning:select name="Location" aura:id="Location">
<aura:iteration items="{!v.Location}" var="loc">
<option value="{!v.loc.Loc__c}">
</option>
</aura:iteration>
Controller :
({
doInit: function(component,event,helper){
var action = component.get("c.getLocation");
action.setCallback(this, function(a){
component.set("v.Location",a.getReturnValue());
});
$A.enqueueAction(action)
},
Class:
public class LocSearchController {
@AuraEnabled
public static List<Location__c> getLocation(){
return [select Loc__c from Location__c];
}
}
Hi Nithya,
Please try the code below.
Please mark it as Best if it helps.
Thanks
Ajay
Thanks for your response. But, the same result is the same, it just gives a blank dropdown.
Thanks Ajay
Hi Ajay,
The code change on line 5 didn't work; but the wrapper class did! Wondering why it didn't work without the wrapper. Any idea?
Thank you very much!
Above code is also working but there is no label for the option value that's why it's not visible.
try this
<option value="{!v.loc}">{!v.loc}</option>
I used here wrapper because we are fetching two different values one is for Picklist value and other is for its name in salesforce org.
Thanks
Ajay Dubedi
No, I tried changing the option value and it again brought back the empty list. There are quite a number of picklists that I'd have to show on the component. Would I have to use the wrapper and label option for all?
Thanks again!