如何访问jade中的js数组数据

how to access data of an js array in jade

我正在使用 twitter-js-client and 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);

我怎样才能做到这一点?

在客户端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);