Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <!----setCallBackCheck.cmp-->
  2. <aura:component controller="LtngServerSideController">
  3. <aura:attribute name="accountName" type="String"/>
  4. <ui:outputText value="{!v.accountName}"/>
  5. <ui:button press="{!c.getName}" label="Get A Name"/>
  6. </aura:component>
  7.  
  8. /*--------setCallBackCheckController.js------*/
  9. ({
  10. getName : function(component, event, helper) {
  11. var action = component.get("c.getAccountName");
  12. $A.enqueueAction(action);
  13. action.setCallback(this,function(response)){
  14. var status = response.getStatus();
  15. if(status === "SUCCESS"){
  16. component.set("v.accountName", response.getReturnValue());
  17. }
  18. }
  19. })
  20.  
  21. /*--------setCallBackCheckController.apxc------*/
  22. public class LtngServerSideController {
  23. @AuraEnabled
  24. public static string getAccountName(){
  25. List<account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
  26. return accounts[0].Name;
  27. }
  28. }
  29.  
  30. ({
  31. getName : function(component, event, helper) {
  32. var action = component.get("c.getAccountName");
  33. // your code as extra closing in the following line as well
  34. action.setCallback(this,function(response){
  35. // you should be using getState on result as getStatus doesn't exist in standard API
  36. var status = response.getState();
  37. if(status === "SUCCESS"){
  38. component.set("v.accountName", response.getReturnValue());
  39. }
  40. // your setCallback wasn't closed properly
  41. });
  42. // you enqueue the action even before it was setup
  43. $A.enqueueAction(action);
  44. }
  45. })
  46.  
  47. getMyContacts : function(cmp) {
  48. var action = cmp.get("c.getContacts");
  49. action.setCallback(this,function(response) {
  50. var status = response.getStatus();
  51. if(status === "SUCCESS"){
  52. cmp.set("v.contacts", response.getReturnValue());
  53. }
  54. });
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement