function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ravichandra sindheRavichandra sindhe 

lightning component combo box

1.Would like to fetch string from table

ex: red,blue,green

2.separate it with comma separator

3.display it a in combo box as a list

 

need a help on how to acheive it in a lightning component

Raj VakatiRaj Vakati
You can able to do it like below 

Refer this link for more info 
https://rajvakati.com/2018/05/10/usage-of-lightningcombobox/
 
public class ContactsController {
    @AuraEnabled
    public static List<String> getDepartment () {
        Set<String> uniqDepartment = new Set<String>();
        List<Contact> results=[Select Id, Department from Contact];
        for(Contact c : results){
            if(c.Department!=null){
                uniqDepartment.add(c.Department); 
            }
        }
        List<String> finalResult =  new List<String>();
        finalResult.addAll(uniqDepartment); 
        finalResult.sort();
        return  finalResult;
    }
    
     
    
    
    
}
 
<aura:component controller="ContactsController">
    <aura:attribute name="statusOptions" type="List" default="[]"/>
    <aura:attribute name="contacts" type="Contact[]" default="[]"/>
    
    <aura:handler name="init" value="{! this }" action="{! c.loadOptions }"/>
    <lightning:combobox aura:id="selectItem" name="status" label="Status"
                        placeholder="Choose Status"
                        value="new"
                        required="true"
                        dropdownAlignment="right"
                        variant="standard"
                        messageWhenValueMissing="You Must Select the Value"
                    
                        options="{!v.statusOptions}"/>
 
    
    
</aura:component>


 
({
    loadOptions: function (cmp, event, helper) {
        var options = [
        ];
        var action = cmp.get("c.getDepartment");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var arr = response.getReturnValue() ;
                arr.forEach(function(element) {
                    options.push({ value: element, label: element });
                });
                cmp.set("v.statusOptions", options);
                
            }
            
            
        });
        $A.enqueueAction(action);
        
    },
   
})