【问题标题】:Making jslink target specific list制作jslink目标特定列表
【发布时间】:2015-05-18 14:39:42
【问题描述】:

背景
我有一个页面,其中显示了来自两个单独列表的两个列表视图,这两个列表都将自定义列表作为其 ListTemplate。他们得到了单独的 jslink 文件,因为我不希望他们看起来很像。

问题
js 链接文件针对两个列表视图,因为它们使用相同的模板。

代码

(function () { 
    var listContext = {}; 
    listContext.Templates = {}; 

    listContext.ListTemplateType = 100;

    listContext.Templates.Header = "<div><ul>"; 
    listContext.Templates.Footer = "</ul></div>"; 
    listContext.Templates.Item = LinkTemplate; 

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(listContext); 

})(); 

问题
有没有办法让js只针对特定的列表?

【问题讨论】:

    标签: sharepoint sharepoint-2013 jslink


    【解决方案1】:

    最终选择了他在 myfatblog.co.uk 上所写的 Paul Hunts 解决方案。 http://www.myfatblog.co.uk/index.php/2013/09/listview-web-part-issues-with-jslink-and-display-templates-a-solution/

    脚本最终看起来像这样,我将其粘贴到 jslink 函数中,在该函数中我定义了要覆盖的 listContext。

    // Override the RenderListView once the ClientTemplates.JS has been called
    ExecuteOrDelayUntilScriptLoaded(function(){
    
        // Copy and override the existing RenderListView
        var oldRenderListView = RenderListView;
    
        RenderListView = function(ctx,webPartID)
        {
            // Check the title and set the BaseViewId
            if (ctx.ListTitle == "List")
                ctx.BaseViewID = "list";
    
            //now call the original RenderListView
            oldRenderListView(ctx,webPartID);
        }
    
    },"ClientTemplates.js");
    

    【讨论】:

      猜你喜欢
      • 2019-03-27
      • 1970-01-01
      • 1970-01-01
      • 2019-12-30
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多