我正在使用jQuery的jTemplates。我希望在没有结果时显示消息,而不是什么都没有。我已经尝试在模板中包含消息并使用{#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;
}
答案 0 :(得分: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}