[英]using SP.js in Office 365 SharePoint Addin
I have used the "sp.js" to access the sharepoint ClientContext in SharePoint 2010 and 2013 webparts. 我已使用“ sp.js”来访问SharePoint 2010和2013 Webparts中的共享点ClientContext。 I want to use the SP ClientContext in my office 365 add-in.
我想在我的Office 365加载项中使用SP ClientContext。
The code i have used, 我使用的代码
ExecuteOrDelayUntilScriptLoaded(function () {
var context = new SP.ClientContext.get_current();
}, "sp.js");
It failed to load the "sp.js" file when i tried it in office 365 SharePoint add-in. 当我在Office 365 SharePoint加载项中尝试加载“ sp.js”文件时,它失败。 How to resolve this issue?
如何解决这个问题? What is the way to use "sp.js" file in office 365 SharePoint add-in?
在Office 365 SharePoint加载项中使用“ sp.js”文件的方式是什么?
EDIT: I am creating the SharePoint hosted add-in. 编辑:我正在创建SharePoint托管的加载项。
EDIT:2 I have created a new SharePoint add-in project in VisualStudio 2015, and it has the html code. 编辑:2我在Visual Studio 2015中创建了一个新的SharePoint加载项项目,它具有html代码。 So, i am unable to use below code in my page,
因此,我无法在页面中使用以下代码,
<SharePoint:ScriptLink ID="ScriptLink1" name="SP.js" runat="server"
ondemand="false" localizable="false" loadafterui="true" />
您能否让我们知道您是在做提供商托管还是SharePoint托管加载项?
In your .aspx page that you are using for the add-in include the following snippet. 在用于外接程序的.aspx页中,包含以下代码段。
<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server"> <SharePoint:ScriptLink Name="sp.js" runat="server" LoadAfterUI="true" Localizable="false" /> </asp:Content>
Add this to the top of the Default.aspx page: 将其添加到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" %>
Then within ContentPlaceHolderID="PlaceHolderAdditionalPageHead" add: 然后在ContentPlaceHolderID =“ PlaceHolderAdditionalPageHead”中添加:
<SharePoint:ScriptLink name="sp.js" runat="server" OnDemand="true" LoadAfterUI="true" Localizable="false" />
Also, your screenshot is of a Provider hosted add-in, not a SharePoint hosted one. 另外,您的屏幕快照是提供程序托管的加载项,而不是SharePoint托管的加载项。 That's why SP.js references were not added automatically.
这就是为什么没有自动添加SP.js引用的原因。 You will likely want to recreate your visual studio solution using the correct add-in settings.
您可能需要使用正确的加载项设置来重新创建Visual Studio解决方案。 A SharePoint Hosted add-in never has a separate web application project within the solution.
SharePoint托管加载项在解决方案中永远不会有单独的Web应用程序项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.