在GSP中格式化html表

时间:2012-12-07 02:55:18

标签: html grails html-table gsp

我正在使用Grails,目前我遇到了这个问题。

这是我的html表的结果 enter image description here

这是我在gsp页面中的代码

    <tr>
        <th>Device ID</th>
        <th>Device Type</th>
        <th>Status</th>
        <th>Customer</th>   
    </tr>
<tr>
<g:each in = "${reqid}">
        <td>${it.device_id}</td>
</g:each>

<g:each in ="${custname}">
        <td>${it.type}</td>
        <td>${it.system_status}</td>
        <td>${it.username}</td>
</g:each>
    </tr>

问题是,如何格式化表格,使“LHCT271,2,Thomasyeo”相应地向下移动?我试图在这里和那里添加<tr>标签,但它不起作用..请帮忙吗?

2 个答案:

答案 0 :(得分:2)

我认为你的问题不在视图中,而是在控制器(或者甚至是域)中。如果reqidcustname位于同一个表格中,您必须知道{{1}}和{{1}}是相关的。您必须使用它来构造一个可以在g中轻松使用的对象:每个

您正在寻找一种混合列和行的方法,并且仍然可以得到一个漂亮的表。我担心这是不可能的。

修改

(抱歉,我刚看到最后一条评论。)

你不能在g中混合两个项目:每个。

此外,如果这两件事情无关,你可能不应该把它们放在同一张桌子里。对于您或Grails来说,无法知道如何正确组织信息

答案 1 :(得分:1)

您是要显示第一个客户端的第一个reqid(三个字段),第二个是否反映第二个,依此类推?那些长度相同的收藏品是什么?

在这种情况下,您可以尝试以下方法:

<tr>
    <th>Device ID</th>
    <th>Device Type</th>
    <th>Status</th>
    <th>Customer</th>   
</tr>
<g:each var="req" in="${reqid}" status="i">
    <tr>
        <td>${req}</td>
        <td>${custname[i].type}</td>
        <td>${custname[i].system_status}</td>
        <td>${custname[i].username}</td>
    </tr>
</g:each>