2

我将 jTemplates 与 jQuery 一起使用。我想在没有结果时显示一条消息,而不是什么都没有。我尝试在模板中包含消息并使用 {#foreach} 循环中的函数来隐藏它,但这不起作用。请告诉我这是可能的!

{#template JobCodeAssignment}
    <tr class="standard normal" id="jobCode-{$T.JobCode.JobCode_ID}-blank">
        <td colspan="5" style="text-align:center;"><em>No users</em></td>
    </tr>
{#foreach $T as JobCodeAssignment}
    <!-- {hideNoUsersMessage($T.JobCodeAssignment.JobCode_ID)} -->
    <tr class="standard {#cycle values=['normal','alternate']}">
        <td class="firstColumn"><strong>{$T.JobCodeAssignment.User.FirstName} {$T.JobCodeAssignment.User.LastName}</strong></td>
        <td>{formatCurrency($T.JobCodeAssignment.HourlyRate)}</td>
        <td>{$T.JobCodeAssignment.ShiftReportRequired}</td>
        <td>{$T.JobCodeAssignment.MileageReportRequired}</td>
        <td class="lastColumn" style="text-align:right;"><img id="jobCodeAssignmentEditButton-{$T.JobCodeAssignment.JobCodeAssignment_ID}" src="Images/pencil-small.png" class="clickable" onclick="editJobCodeAssignmentOpen({#var $T.JobCodeAssignment});" /></td>
    </tr>
{#/for}
{#/template JobCodeAssignment}

function hideNoUsersMessage(jobCode_ID) {
    $('#jobCode-' + jobCode_ID + '-blank').hide();
    return jobCode_ID;
}
4

1 回答 1

1

我想出了如何以完全不同的方式完成我正在寻找的事情,使用循环中的参数来计算记录数。如果循环后为零,则显示消息。

{#template JobCodeAssignment}
    {#param name=count value=0}
{#foreach $T as JobCodeAssignment}
    {#param name=count value=$P.count+1}
    <tr class="standard {#cycle values=['normal','alternate']}">
        <td class="firstColumn"><strong>{$T.JobCodeAssignment.User.FirstName} {$T.JobCodeAssignment.User.LastName}</strong></td>
        <td>{formatCurrency($T.JobCodeAssignment.HourlyRate)}</td>
        <td>{$T.JobCodeAssignment.ShiftReportRequired}</td>
        <td>{$T.JobCodeAssignment.MileageReportRequired}</td>
        <td class="lastColumn" style="text-align:right;"><img id="jobCodeAssignmentEditButton-{$T.JobCodeAssignment.JobCodeAssignment_ID}" src="Images/pencil-small.png" class="clickable" onclick="editJobCodeAssignmentOpen({#var $T.JobCodeAssignment});" /></td>
    </tr>
{#/for}
    {#if $P.count == 0}
    <tr class="standard alternate">
        <td colspan="5" style="text-align:center;"><em>No users</em></td>
    </tr>
    {#/if}
{#/template JobCodeAssignment}
于 2012-05-20T00:43:54.217 回答