为给定数组创建例程表

时间:2014-03-24 09:24:41

标签: mysql grails

我有以下数据:

[[subject1,day1,time 1]],[subject2,day1,time2]]

我希望表格结构为

        time 1          time 2
Sunday  subject1    Subject 2
Monday  subject1    Subject 2

<table id="routineClassTable" class="table table-condensed">
    <thead><tr>
        <td></td>
        <g:each in="${routineTime}" var="r">
        <td class='${r.id}'>${r.timetable.startTime.format("hh:mm")}-${r.timetable.endTime.format("hh:mm")}</td>
        </g:each>
    </tr>
    </thead>
    <g:each var='d' in='${day}'>
        <tr>
           <td class='${d}'>${d}</td>
            <g:each in="${routineTime}" var="rt">

                   <g:each in="${subject}" var="sub">

                       <g:if test="${sub[1]!=''}"><g:set var="value" value="${sub[0]}"></g:set> </g:if>
                       <g:else>--</g:else>

                   </g:each>

                <td class="${d}${rt.id}">  ${value}
                </td>
            </g:each>
        </tr>
    </g:each>
    </table>

这个表结构有什么问题?它在每一列中显示相同的主题。帮助

1 个答案:

答案 0 :(得分:0)

一眼就看出,您必须在<td>内移动<g:each>

<g:each in="${routineTime}" var="rt">
    <g:each in="${subject}" var="sub">
        <g:if test="${sub[1]!=''}">
            <g:set var="value" value="${sub[0]}"></g:set> 
        </g:if>
        <g:else>--</g:else>

        <!-- Display each subject-->
        <td class="${d}${rt.id}">  ${value}</td>
    </g:each>
</g:each>

或简单地说:

<g:each in="${routineTime}" var="rt">
    <g:each in="${subject}" var="sub">
        <g:if test="${sub[1]}">
            <!-- Display each subject-->
            <td class="${d}${rt.id}">  ${sub[0]}</td>
        </g:if>
        <g:else>
            <td class="${d}${rt.id}"> --</td>
        </g:else>
    </g:each>
</g:each>