【发布时间】:2018-09-10 06:50:57
【问题描述】:
我已通过控制器将列表传递给视图。
代码:
model.put("ScheduleList", schedulelist);
return new ModelAndView("EmployeeScheduleResult","message","Welcome "+(String)req.getSession().getAttribute("uname"));
列表有以下内容:
public class ScheduleList {
Date date;
String status;
String color;
//with setters ,getters and constructor.
}
我想以这样的方式打印列表:
.weekday{
background-color:blue;
}
.weekend{
background-color:grey;
}
<html>
<table>
<tr>
<th>MONDAY</th>
<th>TUESDAY</th>
<th>WEDNESDAY</th>
<th>THURSDAY</th>
<th>FRIDAY</th>
<th>SATURDAY</th>
<th>SUNDAY</th>
</tr>
<tr>
<td class="weekday">2018-09-10</td>
<td class="weekday">2018-09-11</td>
<td class="weekday">2018-09-12</td>
<td class="weekday">2018-09-13</td>
<td class="weekday">2018-09-14</td>
<td class="weekend">2018-09-15</td>
<td class="weekend">2018-09-16</td>
</tr>
</table>
</html>
scheduleList 将包含日期、状态和将要显示的颜色。
我想过使用像
这样的spring标签 <c:forEach items="${ScheduleList}" var="temp">
<tr>
<td>${temp.date}</td>
</tr>
</c:forEach>
这只会导致列表仅显示在星期一列上。我将如何以上面列出的方式显示列表?
问题是当日期是工作日或周末时,我不知道如何将 css 类动态添加到 td,也不知道如何从一周中的特定日期开始我的列表。例如,如果我的列表以星期一的日期 2018-09-10 开始,那么我的表格数据应该以星期一开始(如上面的 HTML 代码 sn-p)。
谁能指导我如何解决这个问题?
编辑:
<c:forEach items="${ScheduleList}" var="temp">
<tr>
<td style="background-color: ${temp.color};">${temp.date}
</td>
</tr>
</c:forEach>
此代码会将我在列表中分配的颜色添加到元素,但以水平方式显示列表且星期一日期在星期一等下的问题仍未解决。
【问题讨论】:
-
谁能帮我解决这个问题。
-
我已经动态添加了 css(见编辑),但水平显示列表的问题仍然很重要。
-
通常多少天会包含您的 ScheduleList 列表?
-
它将包含从当前日期开始的 30 天
-
好的,恐怕为了更容易,您需要更改控制器中的列表以发送 N 个列表,按周发送 N 个列表,并从周一至周日订购,或者更改您的视图并就地使用一个表,使用一个内部有 7 个跨度元素的 div,这样它们就可以单独正确地重新定位。
标签: javascript html css spring spring-mvc