I render an ejs page from Node.js server, in ejs I get JSON like:
A[
{
"name1":"abc",
"name2":"xyz",
"2018/05/10":"2",
"2018/05/12":"4",
"2018/05/20":"20"
},
{
"name1":"def",
"name2":"xxx",
"2018/05/10":"23",
"2018/05/12":"34",
"2018/05/20":"0"
},
{.....},
{......}
]
I want to render ejs like:
name1-------name2--------2018/05/10-------2018/05/12-------2018/05/20
abc-------------xyz----------2--------------------------4-------------------20
def------------xxxx----------23-------------------------34----------------0
How to do it?
you can try ways see
//app.js var jsonfile = require('jsonfile');//import library app.get('/lists', function(req, res){ var data=jsonfile.readFileSync("lists.json");//reac file json res.render("show",data); }); //show.ejs <% lists.forEach(function(rows){%> <tr> <td><%=rows.name1%></td> <td><%=rows.name2%></td> <td><%=rows.date1%></td> <td><%=rows.date2%></td> <td><%=rows.date3%></td> </tr> <%})%>
//you can create file json lists.json "lists:[ { "name1":"abc", "name2":"xyz", "date1":"2", "date2":"4", "date3":"20" } ]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.