javascript - how to access data of an js array in jade -
i using twitter-js-client , vis timeline develope timeline,i can tweets , want display in timeline tweets,in index.js, parse json tweets , pass data returned json.parse() function jade , want display data on timeline using jade.
here index.js:
router.get('/data/timeline',function(req,res) { twitter.getusertimeline({screen_name:'ogedik92',count:10},error,function(data) { var tweets = json.parse(data); res.render('vistimeline',{results:tweets}); });
and here vistimeline.jade
doctype html html head title timeline | basic demo style(type='text/css'). body, html { font-family: sans-serif; } script(src='http://visjs.org/dist/vis.js') link(href='http://visjs.org/dist/vis.css', rel='stylesheet', type='text/css') body #visualization script(type='text/javascript'). // dom element timeline attached var container = document.getelementbyid('visualization'); // create dataset (allows 2 way data-binding) var items = new vis.dataset([ {id: 1, content: ''+results[0].text ,start: '2015-04-20'}, {id: 2, content: 'item 2', start: '2013-04-14'}, {id: 3, content: 'item 3', start: '2013-04-18'}, {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-05-19'}, {id: 5, content: 'item 5', start: '2013-04-25'}, {id: 6, content: 'item 6', start: '2013-04-27'} ]); // configuration timeline var options = {}; // create timeline var timeline = new vis.timeline(container, items, options);
how can achieve that?
you can pass variable in client-side js this:
doctype html html head title timeline | basic demo style(type='text/css'). body, html { font-family: sans-serif; } script(src='http://visjs.org/dist/vis.js') link(href='http://visjs.org/dist/vis.css', rel='stylesheet', type='text/css') body #visualization script(type='text/javascript'). // dom element timeline attached var container = document.getelementbyid('visualization'); var results = !{json.stringify(results)}; // create dataset (allows 2 way data-binding) var items = new vis.dataset([ {id: 1, content: ''+results[0].text ,start: '2015-04-20'}, {id: 2, content: 'item 2', start: '2013-04-14'}, {id: 3, content: 'item 3', start: '2013-04-18'}, {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-05-19'}, {id: 5, content: 'item 5', start: '2013-04-25'}, {id: 6, content: 'item 6', start: '2013-04-27'} ]); // configuration timeline var options = {}; // create timeline var timeline = new vis.timeline(container, items, options);
Comments
Post a Comment