我将 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;
}