Does anyone know how to clear a jQuery tmpl() so I can re-populate it? I cant use empty() because i need the rest of the content in the parent. I can use remove, but I need to know how many… wait, i might have just figured it out 🙂
The template looks like this
<table id="lvList" class="grid1">
<tr id="itemtemplatePlaceHolder">
<th>Reference</th>
<th>Address</th>
<th>Country</th>
<th>Postcode</th>
<th>Tel</th>
<th>Fax</th>
<th style="width:50px;">Billing</th>
<th style="width:50px;">Shipping</th>
</tr>
<script id="itemtemplate" type="text/x-jquery-tmpl">
<tr>
<td><a id="${id}" href="address.aspx?id=${id}" oncontextmenu="ContextMenu.Show(this,event); return false;">${reference}</a></td>
<td>${$item.nobreak("address", ", ")}</td>
<td>${country}</td>
<td>${postcode}</td>
<td>${tel}</td>
<td>${fax}</td>
<td>${$item.bool("defaultbilling", "X", "")}</td>
<td>${$item.bool("defaultshipping", "X", "")}</td>
</tr>
</script>
<tr id="footertemplate">
<td colspan="8"> </td>
</tr>
</table>
Answered my own query 🙂 but just in case anyone else has the same problem, he’s what i did
Kept a track of how many items there were in the data list
this.itemcount = data.Count();, then removed all siblings past the placeholder with an index less than the item count$("#itemtemplatePlaceHolder ~ :lt(" + this.itemcount + ")").remove()