【问题标题】:Conditional formatting on a list on sharepoint 2013 using CSR使用 CSR 对 sharepoint 2013 上的列表进行条件格式设置
【发布时间】:2017-07-07 18:30:44
【问题描述】:

我正在尝试让条件格式在 Sharepoint 2013 上的列表上工作,我想要它做的是根据输入的内容更改优先级字段中单词的颜色,例如高 = 红色 低 = 绿色 中 = 橙色

我已经尝试了多种方法,并且查看了很多教程,但是由于我只有 JS 和 CSR 的基本知识,我发现它很难,我知道要应用 JS 文件到 Web 部件,我必须在 Web 部件编辑器的杂项区域中链接文件的地址位置,这只是我遇到问题的代码。

这是我目前所拥有的

 
(function () { 

    var priorityFiledContext = {}; 
    priorityFiledContext.Templates = {}; 
    priorityFiledContext.Templates.Fields = { 
        
        "Priority": { "View": priorityFiledTemplate } 
    }; 
 
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(priorityFiledContext); 
 
})(); 

function priorityFiledTemplate(ctx) { 
 
    var priority = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 
  
    switch (priority) { 
        case "(1) High": 
            return "<span style='color :#f00'>" + priority + "</span>"; 
            break; 
        case "(2) Normal": 
            return "<span style='color :#ff6a00'>" + priority + "</span>"; 
            break; 
        case "(3) Low": 
            return "<span style='color :#cab023'>" + priority + "</span>"; 
    } 
} 

【问题讨论】:

标签: javascript sharepoint-2013


【解决方案1】:

只要您使用的是英文标准任务列表,代码看起来不错(如果不是,您必须将切换块中的优先级字符串更改为您的任务列表正在使用的任何内容)。

您可以使用例如简化部署 CSR 自定义。 Cisar Chrome 浏览器插件。它将在浏览器窗口中写入的更改实时发布到服务器,并将即时创建的 Javascript 文件附加到当前在浏览器中打开的列表中(假设您有权这样做)。

【讨论】:

    猜你喜欢
    • 2019-02-12
    • 1970-01-01
    • 2021-01-29
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-28
    相关资源
    最近更新 更多