Sharepoint 制作jslink目标特定列表
背景Sharepoint 制作jslink目标特定列表,sharepoint,sharepoint-2013,jslink,Sharepoint,Sharepoint 2013,Jslink,背景 我得到了一个页面,其中我显示了两个列表视图,它们来自两个单独的列表,这两个列表都有自定义列表作为其列表模板。他们有各自的jslink文件,因为我不想让他们看起来像 问题 js链接文件以两个ListView为目标,因为它们使用相同的模板 代码 (function () { var listContext = {}; listContext.Templates = {}; listContext.ListTemplateType = 100; list
我得到了一个页面,其中我显示了两个列表视图,它们来自两个单独的列表,这两个列表都有自定义列表作为其列表模板。他们有各自的jslink文件,因为我不想让他们看起来像 问题
js链接文件以两个ListView为目标,因为它们使用相同的模板 代码
(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);
})();
(函数(){
var listContext={};
Templates={};
listContext.ListTemplateType=100;
listContext.Templates.Header=“”;
listContext.Templates.Footer=“
”;
listContext.Templates.Item=LinkTemplate;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(listContext);
})();
问题有没有办法让js只针对一个特定的列表?最终采用了Paul Hunts的解决方案,他在myfatblog.co.uk上写道 脚本最终看起来是这样的,我将其粘贴到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");