0

I'm trying to set value for an lightning:select option. I have used Map to get value from Server and assigned to an map Attribute. Eventhough I'm setting the value to the attribute. It is not getting reflected in the page.

 @AuraEnabled
public static Map<String,String> loadOpportunityValues(Id OpportunityID){
    system.debug('OpportunityID+++++'+OpportunityID);
    Opportunity oppObj = [select id,product_division__c, SFI_ProductFamily__r.name, sfi_ProductGroup__r.name,
                         SFI_ProductHierarchy__r.name from Opportunity where id =: OpportunityId];
    Map<String,String>OppValuesMap = new Map<String,String>();
    if(oppObj.product_division__c!=null)
    OppValuesMap.put('ProductDivision',oppObj.product_division__c);
    if(oppObj.SFI_ProductFamily__r.name!=null)
    OppValuesMap.put('ProductFamily',oppObj.SFI_ProductFamily__r.name);
    if(oppObj.sfi_ProductGroup__r.name!=null)
    OppValuesMap.put('ProductGroup',oppObj.sfi_ProductGroup__r.name);
    if(oppObj.SFI_ProductHierarchy__r.name!=null)
    OppValuesMap.put('ProductHierarchy',oppObj.SFI_ProductHierarchy__r.name);

   return OppValuesMap;
}

and the lightning controller is

       if(recordID === "undefined"){
        alert('new Opportunity');
    }else{

        var action = component.get("c.loadOpportunityValues");
        action.setParams({ OpportunityID : recordID});
        action.setCallback(this, function(response) {
            var state = response.getState();
            console.log('state+++'+state);
            if (state === "SUCCESS") {
                component.set("v.myMap",response.getReturnValue());
                var prodDiv = component.get("v.myMap.ProductDivision");  

                //component.find("selectedProductDivisionValue").set("v.value",prodDiv);
                component.set("v.selectedProductDivision","Amino Acids");  

                var prodFam = component.get("v.myMap.ProductFamily");

                component.set("v.selectedProductFamily",prodFam);   

                var prodGrp = component.get("v.myMap.ProductGroup");

                component.set("v.selectedProdGrp",prodGrp);

                var prodHierarchy = component.get("v.myMap.ProductHierarchy");

                component.set("v.selectedProdHierarchy",prodHierarchy);

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

and the lightning component is

<lightning:select aura:id="selectedProductDivisionValue"  value="{!v.selectedProductDivision}" onchange="{!c.getProductFamilies}" label="Product Division" required="true">
                        <aura:iteration var="option" items="{! v.ProdDivisionValues }">
                             <option value="{!option}">{!option}</option>
                        </aura:iteration>
                    </lightning:select>
                    <lightning:select aura:id="selectedProdFamId"  value="{! v.selectedProductFamily }" onchange="{!c.getProductGroups}" label="Product Family" required="true">
                        <aura:iteration var="option" items="{! v.ProductFamilyValues }">
                             <option value="{!option}">{!option}</option>
                        </aura:iteration>
                    </lightning:select>
                    <lightning:select aura:id="selectedProdGrpId" label="Product Group" value="{! v.selectedProdGrp }" onchange="{!c.getProductHierarchies}" required="false">
                        <aura:iteration var="option" items="{! v.prodGrpValues }">
                              <option value="{!option}">{!option}</option>
                        </aura:iteration>
                    </lightning:select>
                    <lightning:select aura:id="selectedProdHierarchyId" value="{! v.selectedProdHierarchy }" label="Product Hierarchy" required="false">
                        <aura:iteration var="option" items="{! v.prodHierarchyValues }">
                            <option value="{!option}">{!option}</option>
                        </aura:iteration>
                    </lightning:select>
1

Lightning is cAsE sEnSiTiVe. Please check the capitalization of the field names. I can guarantee at least some of them are wrong, as "name" should be "Name".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.