Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

求解 关于一个把json导入ejs的问题

$
0
0

一个例子如下: //index.js doc = {“title”:“ttt”, “content”:[“rrr”, “yyy”]} docs = [] docs.push(doc) docs.push(doc) console.log(docs)

app.get(’/’, function(req, res) { res.render(‘test’, {docs:JSON.stringify(docs)}); }); //ejs <body> <%- docs %> <hr> <%- docs[0] %> <hr> <%- docs.length %> </body> 结果: [{“title”:“ttt”,“content”:[“rrr”,“yyy”]},{“title”:“ttt”,“content”:[“rrr”,“yyy”]}] [ 81 如何把docs里的每个元素显示出来?


Viewing all articles
Browse latest Browse all 14821

Trending Articles