0

我是 JS 新手,所以请耐心等待。我正在制作一个 JSLink 文件以向我的 SharePoint 页面添加条件格式。

我的 SharePoint 页面中有一个日期字段(在 Chrome 调试器模式下查看):

"Calibration_x0020_Due2": "3\u002f31\u002f2020",

我想做一些代码检查日期是否在今天日期前 30 天之后(使背景变为红色)。如果日期距离今天之前的日期超过 30 天,它将显示为绿色。

我正在修改一个函数,该函数根据另一个字段中显示的单词应用条件格式。我不确定如何检查日期。

(function () {

var statusFieldCtx = {};
statusFieldCtx.Templates = {};
statusFieldCtx.Templates.Fields = {
    "Calibration_x0020_Due2": {  //The internal name of that column.
                "View": StatusFieldViewTemplate
        }
};

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(statusFieldCtx);

    function StatusFieldViewTemplate(ctx) { //Function to change the status styling

    var statusValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; //To get the current item's status value.
        if (statusValue < "NOT SURE WHAT TO PUT HERE") {
                return "<div style='background-color:red;color:white'>" + statusValue + "</div>";
        }
        if (statusValue >= "NOT SURE WHAT TO PUT HERE") {
            return "<div style='background-color:green;color:white'>" + statusValue + "</div>";
        }
        else{
                return statusValue;
        }
    }
})();

显然,数学是显而易见的。我只是不知道如何从字符串中提取日期?我已经尝试过statusValue.getMonth(),但它.getMonth is not a function在其他错误中说。

有什么想法吗?

4

0 回答 0