【发布时间】:2018-02-08 00:24:19
【问题描述】:
这里需要一些帮助,我正在尝试将 Json 对象作为 myVar 传递给下面的 home.ejs 文件。我应该如何将值分配给名为 data 的变量?
<table id="example" class="table table-striped table-bordered dataTable" cellspacing="0" width="100%">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">CSI ID</th>
<th scope="col">App Name</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
<!-- Below throws the error -->
<% var data = <%= myVar %>
<% for (var i = 0; i < data.length; i++) { %>
<tr>
<td><%= data[i].id %></td>
<td><%= data[i].name %></td>
</tr>
<% } %>
</tbody>
</table>
错误信息
Could not find matching close tag for "<%".>
app.js
这里的“项目”输出 JSON 数据
app.get("/",function(req,resp) {
client.projects.getAll()
.then(function(projects){
console.log(projects); //buildList.build is an array of builds, from most recent to the count parameter
myJsonData = projects;
});
resp.render('nav', {"page":"home.ejs","myVar":myJsonData});
});
【问题讨论】:
标签: javascript json node.js express callback