Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <aura:component controller="ApexController">
- <aura:attribute name="dataList1" type="String[]" default="[]"/>
- <aura:attribute name="dataList2" type="String[]" default="[]"/>
- <aura:handler name="init" value="{! this }" action="{! c.onInit }" />
- <lightning:select aura:id="select1" label="Select 1" >
- <aura:iteration items="{! v.dataList1 }" var="item">
- <option text="{! item }" value="{! item }" />
- </aura:iteration>
- </lightning:select>
- <lightning:select aura:id="select2" label="Select 2" >
- <aura:iteration items="{! v.dataList2 }" var="item">
- <option text="{! item }" value="{! item }" />
- </aura:iteration>
- </lightning:select>
- </aura:component>
- ({
- onInit: function(component, event, helper) {
- helper.loadDataForSelect1(component);
- helper.loadDataForSelect2(component);
- },
- });
- ({
- loadDataForSelect1: function(component) {
- const action = component.get("c.getdData1");
- action.setCallback(this, function(response) {
- const state = response.getState();
- if (state === "SUCCESS") {
- component.set("v.dataList1", response.getReturnValue());
- } else {
- let errors = response.getError();
- let message = 'Unknown error'; // Default error message
- // Retrieve the error message sent by the server
- if (errors && Array.isArray(errors) && errors.length > 0) {
- message = errors[0].message;
- }
- // Display the message
- console.error(message);
- }
- });
- $A.enqueueAction(action);
- },
- loadDataForSelect2: function(component) {
- const action = component.get("c.getdData2");
- action.setCallback(this, function(response) {
- const state = response.getState();
- if (state === "SUCCESS") {
- component.set("v.dataList2", response.getReturnValue());
- } else {
- let errors = response.getError();
- let message = 'Unknown error'; // Default error message
- // Retrieve the error message sent by the server
- if (errors && Array.isArray(errors) && errors.length > 0) {
- message = errors[0].message;
- }
- // Display the message
- console.error(message);
- }
- });
- $A.enqueueAction(action);
- }
- })
- public with sharing class ApexController
- {
- @AuraEnabled
- public static List<String> getdData1()
- {
- return new List<String> {'One', 'Two', 'Three'};
- }
- @AuraEnabled
- public static List<String> getdData2()
- {
- return new List<String> {'Red', 'Green', 'Blue'};
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement