Jade中的Node.js渲染variables

我想在我的视图中查看所有的URL,但是我得到#{data.id} Cannot read property 'id' of undefined错误的#{data.id} Cannot read property 'id' of undefined

我想创build一个循环并查看我拥有的所有video。

app.js

 app.get('/you', function(req,res) { youtube.where('id', '<', '5689').fetchAll().then(function(data) { res.render('youtube', { mi : data }); }); }); 

这是一个给定ID的输出示例(我改变了res.render res.send来testing我的查询,所以它的工作原理)

 [ { "id": 442, "channel_name": "channelNameredacted", "video_url": "videoURlRedacted", "video_title": "redacted", "status": 1, "date": "redacted" } ] 

youtube.jade

假设我想输出videoID的。

 html head body each data in mi #{data.id} 

这对我有用 –

 var jade = require('jade'), fs = require('fs'); var data = { mi: [ { "id": 442, "channel_name": "channelNameredacted", "video_url": "videoURlRedacted", "video_title": "redacted", "status": 1, "date": "redacted" } ] }; fs.readFile('youtube.jade', 'utf-8', function(error, source){ var html = jade.render(source, data); console.log(html) }); 

youtube.jade

 html head body ul each data in mi li= data.id 

产量

 <html><head></head><body><ul><li>442</li></ul></body></html> 

我像这样解决了。

 app.get('/ind', function(req,res) { youtube.where('id', '<', '100').fetchAll().then(function(data) { data = data.toJSON(); res.render('youtube', { mi : data }); }); }); 

youtube.jade

 html head body ul for m in mi li #{m.id}