动态构建html表头的最佳方法是什么?我有一个描述订单表标题的对象列表。
public final class Header {
private final Long id; // Unique id of the header
private final String label; // Printed in the table header area
private final Boolean enabled; // If this header is enabled or not
private final Short position; // The position in the header i.e 1, 2, 3, etc
// Constructor, and getters. This is a value object so there are no setters.
}
我想传递给我的模板系统(java thymeleaf)一个List并循环遍历列表来构建表结构。我也在使用spring mvc。
任何帮助都会非常好:-)。如果需要任何其他信息,请告诉我。以下是我想要做的一个例子。
<table>
<thead>
<!-- Loop through the List<Header> -->
<tr>
<th th:each="header : ${headers}">
th:text="${header.label}"
</th>
</tr>
</thead>
</table>
答案 0 :(得分:0)
我曾经拿过标题数组
String headers[] = {"a","b","c","d"}
out.println("<table><tr>");
for(i=0;i<headers.length();i++)
{
out.print("<th>" + headers[i] + "</th>");
}
out.println("</tr>");
答案 1 :(得分:0)
这对我有用(在其中使用span-tag):
<tr>
<th th:each="header: ${headers}">
<span th:text="${header.label}"></span>
</th>
</tr>