【发布时间】:2016-02-19 17:02:05
【问题描述】:
我有一个需求,需要在哪里显示 tbody 将是动态的表格。
下面的 JSON 来自 Template 的辅助函数作为返回。
此对象的长度将等于行数。 Cols 的数量是固定的,但列(即 TD)背景应根据您在下面看到的时间和状态更改为红色/绿色。
例如:在下面的 JSON 中,您会看到时间 11 和 12,状态为“使用中”(绿色)、“空闲”(红色),基于此,我的列(第 11 列和第 12 列)背景应该是绿色或红色。
[{
"time": [11, 12],
"status": ["In-Use", "Idle"],
"name": "Book1"
}, {
"time": [12, 13, 14],
"status": ["Idle", "In-Use"],
"name": "Book2"
}]
这可以在流星模板中做到吗?我无法弄清楚如何做到这一点。
下面是我到目前为止提出的模板:
<table class="table" >
<thead>
<tr>
<th scope="col" class="Name"></th>
<th scope="col">06:00</th>
<th scope="col">07:00</th>
<th scope="col">08:00</th>
<th scope="col">09:00</th>
<th scope="col">10:00</th>
<th scope="col">11:00</th>
<th scope="col">12:00</th>
<th scope="col">13:00</th>
<th scope="col">14:00</th>
<th scope="col">15:00</th>
<th scope="col">16:00</th>
<th scope="col">17:00</th>
<th scope="col">18:00</th>
<th scope="col">19:00</th>
<th scope="col">20:00</th>
<th scope="col">21:00</th>
</tr>
</thead>
<tbody>
{{#each getHistory}}
<tr>
<td class="Name">{{name}}</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
{{/each}}
</tbody>
</table>
一个解决方案是编写一个带有背景图像属性的 CSS 红色和绿色,然后添加那些 TD 类,但是如何在模板内构建表格时添加它们?还有其他方法吗?
【问题讨论】:
-
到目前为止您尝试过什么?您没有表现出任何自己解决问题的尝试。
-
@ChristianFritz 我想我的问题并不清楚,无论如何我想对那些第 11 和第 12 TD 使用 addClass ,并且我会写背景:红色/绿色。所以实际的问题是如何根据时间和状态数组添加类?或者如果我们不能在 Template 中编写 addClass 的话,还有什么办法吗?
标签: meteor meteor-blaze