繁体   English   中英

在Office 365 SharePoint外接程序中使用SP.js

[英]using SP.js in Office 365 SharePoint Addin

我已使用“ sp.js”来访问SharePoint 2010和2013 Webparts中的共享点ClientContext。 我想在我的Office 365加载项中使用SP ClientContext。

我使用的代码

ExecuteOrDelayUntilScriptLoaded(function () {
    var context = new SP.ClientContext.get_current();
}, "sp.js");

当我在Office 365 SharePoint加载项中尝试加载“ sp.js”文件时,它失败。 如何解决这个问题? 在Office 365 SharePoint加载项中使用“ sp.js”文件的方式是什么?

编辑:我正在创建SharePoint托管的加载项。

编辑:2我在Visual Studio 2015中创建了一个新的SharePoint加载项项目,它具有html代码。 因此,我无法在页面中使用以下代码,

<SharePoint:ScriptLink ID="ScriptLink1" name="SP.js" runat="server"
    ondemand="false" localizable="false" loadafterui="true" />

这就是我的项目的样子, 这就是我的项目的样子

您能否让我们知道您是在做提供商托管还是SharePoint托管加载项?

在用于外接程序的.aspx页中,包含以下代码段。 <asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server"> <SharePoint:ScriptLink Name="sp.js" runat="server" LoadAfterUI="true" Localizable="false" /> </asp:Content>

将其添加到Default.aspx页面的顶部:

<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

然后在ContentPlaceHolderID =“ PlaceHolderAdditionalPageHead”中添加:

<SharePoint:ScriptLink name="sp.js" runat="server" OnDemand="true" LoadAfterUI="true" Localizable="false" />

另外,您的屏幕快照是提供程序托管的加载项,而不是SharePoint托管的加载项。 这就是为什么没有自动添加SP.js引用的原因。 您可能需要使用正确的加载项设置来重新创建Visual Studio解决方案。 SharePoint托管加载项在解决方案中永远不会有单独的Web应用程序项目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM