Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. <aura:component controller="ApexController">
  2. <aura:attribute name="dataList1" type="String[]" default="[]"/>
  3. <aura:attribute name="dataList2" type="String[]" default="[]"/>
  4.  
  5. <aura:handler name="init" value="{! this }" action="{! c.onInit }" />
  6.  
  7. <lightning:select aura:id="select1" label="Select 1" >
  8. <aura:iteration items="{! v.dataList1 }" var="item">
  9. <option text="{! item }" value="{! item }" />
  10. </aura:iteration>
  11. </lightning:select>
  12.  
  13. <lightning:select aura:id="select2" label="Select 2" >
  14. <aura:iteration items="{! v.dataList2 }" var="item">
  15. <option text="{! item }" value="{! item }" />
  16. </aura:iteration>
  17. </lightning:select>
  18. </aura:component>
  19.  
  20. ({
  21. onInit: function(component, event, helper) {
  22. helper.loadDataForSelect1(component);
  23. helper.loadDataForSelect2(component);
  24. },
  25. });
  26.  
  27. ({
  28. loadDataForSelect1: function(component) {
  29. const action = component.get("c.getdData1");
  30. action.setCallback(this, function(response) {
  31. const state = response.getState();
  32. if (state === "SUCCESS") {
  33. component.set("v.dataList1", response.getReturnValue());
  34. } else {
  35. let errors = response.getError();
  36. let message = 'Unknown error'; // Default error message
  37. // Retrieve the error message sent by the server
  38. if (errors && Array.isArray(errors) && errors.length > 0) {
  39. message = errors[0].message;
  40. }
  41. // Display the message
  42. console.error(message);
  43. }
  44. });
  45.  
  46. $A.enqueueAction(action);
  47. },
  48. loadDataForSelect2: function(component) {
  49. const action = component.get("c.getdData2");
  50. action.setCallback(this, function(response) {
  51. const state = response.getState();
  52. if (state === "SUCCESS") {
  53. component.set("v.dataList2", response.getReturnValue());
  54. } else {
  55. let errors = response.getError();
  56. let message = 'Unknown error'; // Default error message
  57. // Retrieve the error message sent by the server
  58. if (errors && Array.isArray(errors) && errors.length > 0) {
  59. message = errors[0].message;
  60. }
  61. // Display the message
  62. console.error(message);
  63. }
  64. });
  65.  
  66. $A.enqueueAction(action);
  67. }
  68. })
  69.  
  70. public with sharing class ApexController
  71. {
  72. @AuraEnabled
  73. public static List<String> getdData1()
  74. {
  75. return new List<String> {'One', 'Two', 'Three'};
  76. }
  77.  
  78. @AuraEnabled
  79. public static List<String> getdData2()
  80. {
  81. return new List<String> {'Red', 'Green', 'Blue'};
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement