javascript - Returning a value from 'success' block in JS (Azure Mobile Service) -
i have rather simple getuser method i'm having trouble with. not familiar scopes , such in js giving me head ache. want fetch object database , return calling method:
function getuser(uid) { var result = null; var usertable = tables.gettable('users'); usertable.where({ userid: uid }).read({ success: function (results) { if (results.length > 0) { result = results[0]; console.log('userid'+result.id); } } }); console.log('userid-'+result.id); // undefined!! return result; }
also, returning inside success doesn't return getuser, function defined inside. tried "result = function(results)" stores defined function , not return value.
how supposed this?
i found solution elsewhere. in practice (to best of understanding), not possible within javascript asynchronous functions. need create recursion instead inside success handler.
Comments
Post a Comment