forEach不是函数当我在ejs中使用nodejs迭代json文件时在迭代时给出一些错误..下面是我在.ejs文件,json和nodeJS中完成的三个部分
这是我的JSON数据
<pre>
{
"MenuName": "Main Menu Here",
"widget": {
"window": {
"data": "Click Here",
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"window": {
"data": "Click Here",
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"window": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}
}
</pre>
这是我的ejs
<html>
<head>
<title><%= title %></title>
</head>
<body>
<h1> My Name Is <%= title %></h1>
<h1> My Name Is <%= printIt.MenuName %></h1>
<ul>
<% printIt.widget.forEach(function(item){%>
<li><%= item.window.data%></li>
<% }); %>
</ul>
</body>
</html>
</pre>
<pre>
app.locals.printIt = require("./sample.json");
</pre>
I can able to print
My Name Is <%= title %> and My Name Is <%= printIt.MenuName %>
What i missed here..?
答案 0 :(得分:0)
首先,您的JSON数据将仅保留窗口小部件窗口的单个记录,哪个是最后一个。因为窗口键将覆盖先前的保持值。
使用此脚本更新您的脚本
commons-httpclient-3.1.jar
commons-codec-1.10.jar
commons-logging-1.2.jar
希望这有助于解决您的疑问!!