I m using the jQuery template plug-in (official jquery-tmpl plugin) to build up a an HTML list. The template basically defines <li>
elements and looks something like this:
<script id="item-display-template"> type="text/html">
<li>
<div class="item-display-container">
<p>${SomeData1} .... ${SomeData2} etc....</p>
<a onclick="editRow();">Edit This Item</a>
</div>
</li>
</script>
Each item in the resulting list will have an Edit This Item link that will invoke an editRow function. I need to be able to provide this function with the primary key (id) of the database record for the item being edited. The id is included in the JSON being bound to the template. My first thought was to do this with the Edit This Item link:
<a onclick="editRow(${Id});">Edit This Item</a>
I think that will work, but I m not sure that this is the "right way".
Is it possible to invoke the jQuery.data() method within the template to attach the Id value to one of the DOM elements as the template is being rendered?