javascript - async call in jade template -
My web app contains a master jade template that contains all the main components to load on each page of the app. One of the novars I have divided into another template. This navbar has a dropdown that needs to be dynamically populated with DB.
The problem I am experiencing is that I want to populate the dropdown at that time while the Nabar Bar is provided because I am using Express 4.0 with NodeJSS, I have a supporting function Which would populate the list directly inside the navbar template. Because this function is async, however, the drop-down item render itself nine times even before it is received from DB.
I also thought to use AJAX on page loads or even just pre-templates the dropdown item, but I have to call each res.render () in my controllers on this Do not want to go to the list.
What is the best way to go about doing this?
sample templates
master.jade:
doctype html html (lang = n) head block title body # Navier block headerContent #content block content in header
navbar.jade:
... // nav code li ( Class = 'dropdown list duration (class =' care ') ul (class =' dropdown menu ', role =' menu ') (' href = '#', class = 'dropdown-toggle', data-toggle = 'Dropdown') Li values each value, a list in the list (href = '#')
A typical page bus master template in the system
Thank you!
Edit:
Add a sample controller to show a render call
sampleController.js:
... some error investigation model.save (function (error, result) {if (err) res.render (' Resend ('View', {data: * formatted results obj *})
Data is particularly related to content Must be provided on this special scene and Not necessarily what is required by the master. I do not even want to pass in navbar items.
AJX seems impractical for one to navbar.
You can use a middle class to populate the locals' objects
app.use (function (req, res, next) {res.locals .list = [...]; // or app.locals.list = [...]; Next ();});
Comments
Post a Comment