mercredi 28 janvier 2015

Variable Scope Issue in JSonStore Callback

I have a json store to return a json string into the call back function without any problem. However, I failed to pass the returned values into an array. Any guru could point me what I am doing wrong in the code below:

var studentArray = [];


store.load({

scope: this,

callback: function (records, options, success) {

if (success) {

for (var i=0; i < records.length; i++) {

studentArray.push(records[i].data.studentid);

}

}

alert("You have " + studentArray.length + " added"); // First alert

}

});


alert("You finally have: " + studentArray.length); // Second alert


In the Second alert, I always got "You finally have 0". Believe I have a variable scope problem. How could I get over this problem?


Thank you very much?






Variable Scope Issue in JSonStore Callback

Aucun commentaire:

Enregistrer un commentaire