I am using express.js for my application, i want to retrieve data from my mongodb and store it in a variable in my jade file, then i will use this variable to draw charts using dygraph.
doctype html html head title siddh link(rel='stylesheet', href='/stylesheets/style.css') script(type='text/javascript', src='http://cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.1/dygraph-combined.js') body #graphdiv(style="width:1000px; height=700px;") script(type='text/javascript'). each doc, i in docs
. i am getting error in last line after each and it says "expecting newline or semicolon". And below is the javascript file for routing.
exports.getData = function(req,res){ var db = req.db; var collection = db.get('collection'); collection.find({},{},function(e,docs){ res.render('index1.jade',{docs:docs}); }); }
I searched the internet but i am not getting any relevant data, and as a guide for node,mongo and express i am following this tutorial : cwbuecheler.com/web/tutorials/2013/node-express-mongo/
In your docs either put _id
as a string or remove that, that's an invalid json, test it at http://codebeautify.org/jsonvalidate , make it to string.
Then try this:
doctype html
html
head
title siddh
link(rel='stylesheet', href='/stylesheets/style.css')
script(type='text/javascript', src='http://cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.1/dygraph-combined.js')
body
#graphdiv(style="width:1000px; height=700px;")
ul
each val,i in docs
li= val['_id']
li= val['Date']
li= val['TTFB']
And if you want it in graphdiv put JavaScript code as it is, you may test it here http://jade-lang.com/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.