【发布时间】:2018-08-14 15:42:49
【问题描述】:
我必须从一个 json 文件(实际上是 2 个 json 文件)做一个 ForEach,因为这个原因我做了 2 个 forEach,代码是
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<h2>HTML Table</h2>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<% alist.forEach(function(alist_items){%>
<% alist_b.forEach(function(alist_items_b){%>
<%if(alist_items_b.AY==alist_items.CI){ %>
<tr>
<td bgcolor="#FF0000"><%= JSON.stringify(alist_items_b) %></td>
</tr>
<% }else{ %>
<tr>
<td><%= JSON.stringify(alist_items_b) %></td>
<% } %>
</tr>
<% }) %>
<% }) %>
</table>
json文件是:
[
{
"CI": "10"
},
{
"CI": "11"
},
{
"CI": "12"
},
{
"CI": "13"
},
{
"CI": "14"
},
{
"CI": "15"
},
{
"CI": "16"
},
{
"CI": "17"
},
{
"CI": "18"
},
{
"CI": "19"
},
{
"CI": "20"
}
]
和
[\[
{
"AY": "10"
},
{
"AY": "11"
},
{
"AY": "12"
},
{
"AY": "13"
},
{
"AY": "14"
}
我需要用红色显示重复值,通常是其他值,但是您如何在1 图片中看到,其他值重复多少次作为重复。 我只需要显示一次其他值
谢谢
【问题讨论】:
标签: javascript arrays node.js foreach ejs