javascript - Why is my variable not in the scope I believed it should be? -
in example below, first alert print whereas second 1 not. need use ctx.executequeryasync perform number of operations, need use updated value of "titles" after ran. if try afterwards, console says "titles" undefined or blank. have been able update variables in loops throughout rest of code, , remaining piece.
this being used on sharepoint list way.
function dostuff() { var titles = []; for(var = 0; < selecteditems.length; i++) { var id = selecteditems[i].id; var item = list.getitembyid(id); items.push(item); ctx.load(item, "title"); } if (items) { ctx.executequeryasync(function() { for(var j = 0; j < items.length; j++) { titles.push(items[j].get_item("title")); } alert(titles.tostring()); }, function(sender, args){ alert('request failed. ' + args.get_message() + '\n' + args.get_stacktrace()); }); } alert('titles '+titles.tostring()); }
function dostuff() { var titles = []; for(var = 0; < selecteditems.length; i++) { var id = selecteditems[i].id; var item = list.getitembyid(id); items.push(item); ctx.load(item, "title"); } if (items) { ctx.executequeryasync(function(titles) { return function() { for(var j = 0; j < items.length; j++) { titles.push(items[j].get_item("title")); } alert(titles.tostring()); }, function(sender, args){ alert('request failed. ' + args.get_message() + '\n' + args.get_stacktrace()); } }(titles)); } alert('titles '+titles.tostring()); }
Comments
Post a Comment