javascript - Variable not working outside method -


i trying access db results node/express.js on parse.com because have additional data loop next. need navigation table loop, , inside loop loop table. proper way? cannot access variable navigation outside of method below:

var navigation = parse.object.extend('navigation'); var navigation; var query = new parse.query(navigation); query.ascending('sortorder'); query.find().then(function(results) {     navigation = results }, function() {     res.send(500, 'failed loading navigation'); });  res.render('index', { nav: navigation }); 

thoughts? building mobile single page app. don't need routes. want loop through , build navigation. , loop through , build other div's shown/hidden according user selects navigation. hope makes sense.

as written, navigation being assigned value during callback async function...after passed renderer. @ time render called, navigation has been declared, not yet given value.

any time assign value part of async callback, every operation wish make use of value has either part of callback or happen after (for instance, in subsequent chained .then())

in case, can move render call callback , should sufficient.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -