在SharePoint 2013上,我在列表中的字段遇到麻烦,我通过schema.xml文件定义该字段。我们从2007年升级到可以正常工作,但升级到2013年后,从新版本创建列表时不再有效。
历史:
该字段是一个自定义字段,用于输出包含链接的图像,该链接使用javascript动态显示。这是使用display pattern和cdata定义的。
我们在schema.xml文件中定义了以下字段:
<Field ID="{A54A4AE0-CA79-47b0-819E-32DC1B3F5AFB}" ReadOnly="TRUE" Type="Computed" Name="Book" Sortable="FALSE" Filterable="FALSE" DisplayName="Book" ClassInfo="Icon" AuthoringInfo="(link to book item)" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Book" FromBaseType="TRUE">
<DisplayPattern>
<HTML><![CDATA[<a href="javascript:" OnClick="javascript:this.href=L_Menu_BaseUrl + '/Lists/Bookings/NewForm.aspx?Session_x0020_Name=]]></HTML>
<Column Name="ID" />
<HTML><![CDATA[';GoToLink(this);return false;" target="_self">]]></HTML>
<HTML><![CDATA[<img border="0" alt="]]></HTML>
<HTML>Book</HTML>
<HTML><![CDATA[" src="/_layouts/images/Book.GIF">]]></HTML>
<HTML><![CDATA[</a>]]></HTML>
</DisplayPattern>
</Field>
当使用此架构从new启动列表时,它不再有效,它会创建book字段,但它只是空白。
我尝试过:
经过研究,我了解到自定义字段现在应该用xsl文件定义:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\XSL
所以我创建了一个名为fldtypes_Book.xsl
其中的内容如下所示(目前我只想输出简单的文字以使其正常工作):
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
version="1.0"
exclude-result-prefixes="xsl msxsl ddwrt"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:ddwrt2="urn:frontpage:internal">
<xsl:template match="FieldRef[@ID='A54A4AE0-CA79-47b0-819E-32DC1B3F5AFB']" mode="Computed_body" priority="1">
<xsl:param name="thisNode" select="."/>
<span>Hello.</span>
</xsl:template>
</xsl:stylesheet>
再次这不起作用,它只输出字段但字段为空。
我知道该字段与xsl文件挂钩,因为如果我输入一些错误的标签或随机混乱到文件列表中断。
24/08/2015 - 更新
经过研究,我发现了这个:
https://msdn.microsoft.com/en-us/library/office/jj220061.aspx
并尝试将js文件上传到母版页并在列表Web部件设置上链接到它,但没有任何反应,我的js文件的内容:
(function () {
// Initialize the variables for overrides objects
var overrideCtx = {};
overrideCtx.Templates = {};
// alert("Override call worked");
// Use BaseViewID and ListTemplateType to narrow focus/scope on
// which web parts on the page are affected
// overrideCtx.BaseViewID = 1;
// overrideCtx.ListTemplateType = 100;
/*
* Using the Fields override leaves the rest of the rendering intact, but
* allows control over one or more specific fields in the existing view
*/
overrideCtx.Templates.Fields = {
'Book': { 'View' : 'Hello' }
};
/*
* Register the template overrides.
*/
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
非常感谢任何帮助。
答案 0 :(得分:0)
尝试在DisplayPattern定义之前放置已使用字段的FieldRef(同样,确保也定义了这些字段),如下所示:
public class AuditHandler {
public void auditRequest(String appName, ServletRequest request) {
System.out.println(appName + ": Received request from " + request.getRemoteAddr() );
}
}
public class AuditFilter implements Filter {
private final AuditHandler auditHandler;
private String appName;
public AuditFilter(AuditHandler auditHandler) {
this.auditHandler = auditHandler;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
auditHandler.auditRequest(appName, request);
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
appName = filterConfig.getInitParameter("appName");
}
public void destroy() {}
}
ApplicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="auditHandler" class="com.deadcoderising.AuditHandler">
</bean>
<bean id="auditFilter" class="com.deadcoderising.AuditFilter">
<constructor-arg ref="auditHandler"/>
</bean>
</beans>
web.xml
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true">
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
<filter>
<filter-name>auditFilter</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>appName</param-name>
<param-value>di-example</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
不要忘记重新创建列表,这将有助于sharepoint“查看”您的更新。祝你好运!