背景
我得到了一个页面,其中显示了来自两个单独列表的两个列表视图,它们都将自定义列表作为它们的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只针对特定的列表?
发布于 2015-05-18 06:39:42
最后,他使用了保罗·亨特( Paul )在myfatblog.co.uk上写的解决方案。http://www.myfatblog.co.uk/index.php/2013/09/listview-web-part-issues-with-jslink-and-display-templates-a-solution/
脚本最后看起来是这样的,我将它粘贴到jslink函数中,在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");https://stackoverflow.com/questions/30257486
复制相似问题