1

I'm rendering a table with jquery-tmpl, and I don't get how to do a pyjama. Basically what I want is set the class "shadowed" to the items with a index%2==0.

I'm trying with this code, but apparently I have a little mess with the jquery-tmpl syntax:

<script id="theCommentTemplate" type="text/x-jquery-tmpl">
    <tr {{if ${$item.dataArrayIndex($item.data)} %2==0 }} 
                          class="shadowed" 
                    {{/if}}><td>${Reviewer}</td><td>${Date}</td><td>${StatusFrom}</td><td>${StatusTo}</td><td>${Comments}</td></tr>
</script>

And this is the call:

    $.getJSON('@Url.Action("GetPhotoAudit","Photos")/' + id, function (jsonData) {

        $('#theCommentTemplate').tmpl(jsonData,
        {
            dataArrayIndex: function (item) {
                return $.inArray(item, jsonData);
            }
        }
        ).appendTo("#audit tbody");
    });

What would be the correct syntax?

Community
  • 1
  • 1
vtortola
  • 34,709
  • 29
  • 161
  • 263

1 Answers1

1

Do you have to do this within the template code?

Can you not just use the :odd or :even psuedoclass selectors to add the class.

For example:

$("#mytable>tbody>tr:even").addClass("shadowed");
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
  • Yes, I knew this way, but I want to do it with tmpl because I want to know how to do it. Thanks anyway! – vtortola May 11 '11 at 13:42