Last active
January 21, 2016 13:28
-
-
Save keirbowden/12aeb7aa62f07132c2a7 to your computer and use it in GitHub Desktop.
Lightning Component Helper for the Lightning Account Wrappers blog post
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
({ | |
init : function(cmp, ev) { | |
var action = cmp.get("c.GetAccountNames"); | |
action.setCallback(this, function(response) { | |
var state = response.getState(); | |
if (state === "SUCCESS") { | |
var accs=response.getReturnValue() | |
var wrappers=new Array(); | |
for (var idx=0; idx<accs.length; idx++) { | |
var wrapper = { 'acc' : accs[idx], | |
'selected' : false | |
}; | |
wrappers.push(wrapper); | |
} | |
cmp.set('v.wrappers', wrappers); | |
} | |
else if (state === "ERROR") { | |
alert('Error : ' + JSON.stringify(errors)); | |
} | |
}); | |
$A.enqueueAction(action); | |
}, | |
getAccounts : function(cmp, ev) { | |
var action = cmp.get("c.GetAccountDetails"); | |
var wrappers=cmp.get('v.wrappers'); | |
var ids=new Array(); | |
for (var idx=0; idx<wrappers.length; idx++) { | |
if (wrappers[idx].selected) { | |
ids.push(wrappers[idx].acc.Id); | |
} | |
} | |
var idListJSON=JSON.stringify(ids); | |
action.setParams({ | |
"idListJSONStr": idListJSON | |
}); | |
action.setCallback(this, function(response) { | |
var state = response.getState(); | |
if (state === "SUCCESS") { | |
var accs=response.getReturnValue() | |
cmp.set('v.accounts', accs); | |
} | |
else if (state === "ERROR") { | |
var errors = response.getError(); | |
alert('Error : ' + JSON.stringify(errors)); | |
} | |
}); | |
$A.enqueueAction(action); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment