a today, i´m learning lightning, and i block with asyncronous callback. To practice, i did a small helper with apex call and a callback, but when a update a var out of callback, the value in callback changes. My code is:
getTestList: function (cmp) {
var action = cmp.get('c.getTestList');
var counter
for (counter = 0; counter <= 5; counter+=1) {
action.setCallback(this, function (response) {
var state = response.getState();
if (state === 'SUCCESS') {
// do something
}
console.log(counter);
});
$A.enqueueAction(action);
}
}
Thanks.