我正在使用twitter-js-client和vis timeline开发时间轴,我可以获得推文,我想在时间轴中显示推文,在index.js中,我解析json以获取推文和我将JSON.parse()函数返回的数据传递给jade,我希望使用jade在时间轴上显示该数据。
这是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});
});
,这是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 where the Timeline will be attached
var container = document.getElementById('visualization');
// Create a DataSet (allows two 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 for the Timeline
var options = {};
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
我怎样才能实现这一目标?
答案 0 :(得分:1)
您可以在客户端JS中传递变量,如下所示:
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 where the Timeline will be attached
var container = document.getElementById('visualization');
var Results = !{JSON.stringify(Results)};
// Create a DataSet (allows two 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 for the Timeline
var options = {};
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);