Created
October 2, 2019 09:46
-
-
Save olopsman/77eb6f0425514a9c202af8b6242d1c17 to your computer and use it in GitHub Desktop.
Lightning Component Helper that parses the JSON payload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
fetchData: function (cmp) { | |
var action = cmp.get('c.getDocumentList'); | |
action.setCallback(this, $A.getCallback(function (response) { | |
var state = response.getState(); | |
if (state === "SUCCESS") { | |
if(JSON.parse(response.getReturnValue()) != null) { | |
var actions = [ | |
{ label: 'Download', name: 'download' }, | |
]; | |
cmp.set('v.mycolumns', [ | |
{ | |
label: 'Date', | |
fieldName: 'Date', | |
type: 'date' | |
}, | |
{ label: 'Description', fieldName: 'Description', type: 'text'}, | |
{ label: 'FileName', fieldName: 'FileName', type: 'text'}, | |
{ type: 'action', typeAttributes: { rowActions: actions } } | |
]); | |
cmp.set('v.mydata', JSON.parse(response.getReturnValue())); | |
} else { | |
cmp.set("v.noResults", "No records to display"); | |
} | |
} else if (state === "ERROR") { | |
var errors = response.getError(); | |
console.error(errors); | |
cmp.set("v.noResults", "An error occurred: No records to display"); | |
} | |
})); | |
$A.enqueueAction(action); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment