簡體   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