I am trying to create a service component as illustrated in Trailhead
In this module it was given for one field which works beautifully. But let's say I have 5 different picklist fields on the Lightning component UI. So in that situation I am trying accomplish the concept but stuck in how to define the aura:attribute. If I define the way it is given here it is retrieving the values for the last called "v.picklistValues" for all of the fields.
<***** Picklist Component******>
<aura:component controller="PickListController" access="global" description="PickListValues">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="sObjectName" type="String" />
<aura:attribute name="fieldName" type="String" />
<aura:attribute name="picklistValues" type="Object" />
</aura:component>
****Picklist Controller****
({
doInit : function(component) {
var action = component.get("c.getPickListValuesIntoList");
action.setParams({
objectType: component.get("v.sObjectName"),
selectedField: component.get("v.fieldName")
});
action.setCallback(this, function(response) {
var list = response.getReturnValue();
component.set("v.picklistValues", list);
})
$A.enqueueAction(action);
}
})
<***** Parent Component calling Picklist component******>
<c:PicklistValues sObjectName="Executive_Snapshot__c" fieldName="Field1" picklistValues="{!v.picklistValues}" />
<c:PicklistValues sObjectName="Executive_Snapshot__c" fieldName="Field2" picklistValues="{!v.picklistValues}" />
Best Answer
When you add following code
you are passing
picklistValues
attribute from parent componentso if you want to add another one add another parent component attribute and pass that as parameter
your component will look like this