有没有人找到一种方法可以默认自动将jslink URL添加到列表中,而不必在创建时手动将URL添加到每个列表?最终,我们希望编辑可以访问的每种类型的应用都有默认的jslink。
答案 0 :(得分:0)
是的,Chris O' Brien在这里完美地描述了这一点:http://www.sharepointnutsandbolts.com/2013/01/using-jslink-to-change-ui-of-sharepoint_20.html
短篇小说 - 您应该创建列表模板并在那里定义jslink,因此基于此模板的所有列表都将具有js链接。如果您不想以任何理由使用模板来列出列表,则应该查看事件接收器。 (对于List创建的事件。)
答案 1 :(得分:0)
另一种解决方案是编写自己的代码来更新所有页面。 在此页面上 Tobias Zimmergren 显示了使用PowerShell更新JSLink的代码: PowerShell: Configure the JSLink property of a Web Part
我个人使用C#CSOM在所有请求的页面上更新JSLink。 以下是在一个页面上更新JSLink的示例代码(为简单起见,我删除了异常处理和所有非快乐路径逻辑):
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.WebParts;
void UpdateWebPart(ClientContext webpartContext, string RelativeUrl, string JSLink)
{
File page = webpartContext.Web.GetFileByServerRelativeUrl(RelativeUrl);
LimitedWebPartManager wpm = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
webpartContext.Load(page);
webpartContext.Load(wpm.WebParts, wps => wps.Include(w => w.WebPart.Title, w => w.WebPart.Properties));
webpartContext.ExecuteQuery();
if (wpm.WebParts.Count > 0)
{
// You can find your WebPart inside wpm.WebParts e.g. by Title. On each page I have only 1 WebPart, so I just take the first.
WebPartDefinition wpd = wpm.WebParts[0];
WebPart myWP = wpd.WebPart;
if ((string)myWP.Properties["JSLink"] != JSLink)
{
myWP.Properties["JSLink"] = JSLink;
wpd.SaveWebPartChanges();
webpartContext.ExecuteQuery();
}
}
}