GenerateIIDForListItem重设null

时间:2019-08-21 09:25:16

标签: jquery sharepoint csr

我是CSR的新手,我想根据状态对整个Sharepoint列表行进行编码, 但是代码返回null,如下所示:

 for (var i=0;i<rows.length;i++)
       {
          var status = rows[i].Request_x0020_Status;
          var rowId = GenerateIIDForListItem(ctx, rows[i]);//return rowID as (0,421,0)
          var row = document.getElementById(rowId);//returns null
          if(status=="Rechazado")
      {}
          //row.style.backgroundColor = "#b1b1b1";
       }

1 个答案:

答案 0 :(得分:0)

使用此JSLink代码根据“请求状态”列为整个行着色:

<script type="text/javascript">
(function() {  
    var overrideCurrentContext = {};  
    overrideCurrentContext.Templates = {};  
    overrideCurrentContext.OnPostRender = HighlightProductRows;  
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);  
})();  


function HighlightProductRows(ctx) {  
    var statusColors = {  
        'Rechazado': '#b1b1b1',  
        'Pending': '#FFD800',  
        'Completed': '#01DF3A'  
    };  

    var rows = ctx.ListData.Row;  
    for (var i = 0; i < rows.length; i++) {  
        console.log(rows[i]);
        var status = rows[i]["Request_x0020_Status"];  
        var rowId = GenerateIIDForListItem(ctx, rows[i]);
        console.log(rowId);  
        var row = document.getElementById(rowId);  
        row.style.backgroundColor = statusColors[status];  
    }  
}
</script>

这是rowId和row的渲染结果和开发者控制台数据: enter image description here