SharePoint 2013 列表列标题修改 javascript

SharePoint 2013 list column title modification with javascript

我想修改 javascript 视图中的 SharePoint 2013 列表列标题。我在 Whosebug 上找到了一段代码,但我想用显示名称/内部名称引用列,而不是列位置。

(function () {


    function preTaskFormRenderer(renderCtx) {
       modifyHeaderData(renderCtx);       
    }


    function modifyHeaderData(renderCtx)
    {
      var viewTitle = renderCtx.viewTitle;
      var linkTitleField = renderCtx.ListSchema.Field[1];
      linkTitleField.DisplayName = viewTitle + ':' + linkTitleField.DisplayName;
    }

    function registerRenderer()
    {
      var ctxForm = {};
      ctxForm.Templates = {};
      ctxForm.OnPreRender = preTaskFormRenderer;
      SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
    } 
    ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');

})();

示例:

SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {

   SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
     OnPreRender: function(ctx) {

        var field = getFieldByDisplayName(ctx,"Task Name"); 
        if(field)
            field.DisplayName = "Task Name:::"; 
     }
   }); 

});


function getFieldByDisplayName(ctx,name)
{
    var result  = ctx.ListSchema.Field.filter(function(f){return f.DisplayName == name;} ); //find field by display name
    return result.length > 0 ? result[0] : null;
}

结果