【发布时间】:2019-10-07 20:51:02
【问题描述】:
我的 nodeJS 项目中有一个表,其中包含带有状态的数据。我想用红色和绿色显示这个状态。为了呈现 HTML 页面,我使用 EJS。
我已经尝试过使用 if/else 语句,但我总是得到语句的第一个值。
MySQL:
SELECT g_id, g_name, g_status FROM games
EJS:
<table class="table table-hover">
<thead>
<tr class="table-info">
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<% if (data) {
data.forEach(function(game){
var status = game.g_status;
if (status = '1') {
status = 'color-green';
} else {
status = 'color-red';
}
%>
<tbody id="myTable">
<tr>
<td><%= game.g_name %></td>
<td><%= status %></td>
</tr>
</tbody>
<% }) %>
<% } %>
</table>
出了什么问题,如何将 SQL 输出转换为特定颜色?
【问题讨论】:
-
不应该是:if (status == '1') { ?
-
是的,没错,我可能忽略了
标签: javascript html mysql node.js ejs