0

I am new to Lightning Page, so I don't know how to display Custom Object field in Combobox? Is there a way that similar to how it functions in ApexCode? I have this lightning component code:

<lightning:comboBox label="Lớp"
                    options={options}
                    onchange={handleChange}></lightning:comboBox>

and js code but don't know what I should write in it:

({
    myAction : function(component, event, helper) {
        
    }
})

I used to do the same thing back in Visualforce Pages. Visualforce:

<apex:selectList value="{!hs.LOP__c}" size="1" multiselect="false">
                        <apex:selectOptions value="{!lop}"/>
                    </apex:selectList>

ApexCode:

public List<SelectOption> getlop()
    {
        List<SelectOption> options = new List<SelectOption>();
        List<LOP__c> dsLop = [SELECT ID, TEN__c FROM LOP__c ORDER BY TEN__c];
        for(LOP__c lop : dsLop)
        {
            options.add(new SelectOption(String.valueOf(lop.ID), lop.TEN__c));
        }
        
        return options;
    }

I need some help. Thank you.

1 Answer 1

0

You can create the similar apex class but with a list and return it.

In the JS, you need to create a objects list and iterate over the string list and in the objects is necessary to fill a label and value.

Similar to this:

var lops = [];
if(lopLst.length > 0){
    for (var i = 0; i < issueOpt.length; i++){
        
        var item = {
            "label": lopList[i],
            "value": issueOpt[i]
        };
        lops.push(item);                            
    }
}
1
  • I don't understand your answer. Can you explain it more specifically for me? Thank you.
    – Hung Doan
    Apr 1, 2022 at 10:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .