GenerateIIDForListItem 返回 null
GenerateIIDForListItem returing null
我是 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";
}
使用此 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 的渲染结果和开发者控制台数据:
我是 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";
}
使用此 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 的渲染结果和开发者控制台数据: