2

What is the best way to associate a primary key with a table row when using client-side templates, like jQuery Templates?

Should I do some kind of data binding or something? Or should I embed and hide the id in the table like this:

<script id="contactsTemplate" type="text/x-jquery-tmpl">
  <table class="contacts">
    <thead><tr><td class="ui-helper-hidden">Id</td><td>Name</td><td>City</td><td>State</td></tr></thead>
    <tbody>
    {{each contact}}
        {{tmpl($value) '#contactTemplate'}}
    {{/each}}
    </tbody>
  </table>
</script>

<script id="contactTemplate" type="text/x-jquery-tmpl">
    <tr><td class="ui-helper-hidden">${id}</td><td>${name}</td><td>${city}</td><td>${state}</td></tr>
</script>

Isn't it bad to have my Ids accessible to the user, even if they are hidden? What other options do I have?

Homer
  • 7,594
  • 14
  • 69
  • 109

1 Answers1

0

Use an HTML5 custom data attribute, like so

<tr data-id="${id}">...</tr>

For more on HTML5 custom data attributes, see

Community
  • 1
  • 1
rdworth
  • 1,052
  • 7
  • 9
  • I probably should have put this in the question, but I'm concerned about having my Ids accessible to the user, even if they are hidden. – Homer Dec 14 '10 at 17:43
  • You can't deliver something to the client without the client having it. – rdworth Dec 28 '10 at 22:10