一个例子如下: //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里的每个元素显示出来?