【问题标题】:Set a class or not depending of the item index根据项目索引设置或不设置类
【发布时间】:2011-08-23 03:26:15
【问题描述】:

我正在使用 jquery-tmpl 渲染一个表格,但我不知道如何做睡衣。基本上我想要的是将类“隐藏”到带有index%2==0 的项目。

我正在尝试with this code,但显然我对 jquery-tmpl 语法有点混乱:

<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>

这是电话:

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

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

正确的语法是什么?

【问题讨论】:

    标签: jquery jquery-templates


    【解决方案1】:

    您必须在模板代码中执行此操作吗?

    你能不能只使用:odd:even psuedoclass 选择器来添加类。

    例如:

    $("#mytable>tbody>tr:even").addClass("shadowed");
    

    【讨论】:

    • 是的,我知道这种方式,但我想用 tmpl 来做,因为我想知道怎么做。还是谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-23
    • 1970-01-01
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    相关资源
    最近更新 更多