问题描述
hi
我使用MSDN示例制作包含人物选取器控件的应用程序,并将其转换为应用程序部分,以便可以在SharePoint页面中使用它。
I have used the MSDN sample to make app containing People Picker control, and convert it into an App part so that it can be used in SharePoint pages.
MSDN示例位于此处: 人员
选择器控件。
The MSDN sample is located here : People Picker control .
MSDN示例未完成ClientWebPart部分,我完成了它使用以下代码:
The MSDN sample did not complete the ClientWebPart portion, and I completed it with the following code:
People选择器项目已部署并作为SharePoint托管应用程序正常运行。但是,一旦将其作为SharePoint应用程序部件加载并放入SharePoint页面,People选择器控件就不会呈现。
The People picker project deployed and worked fine as a SharePoint hosted app. But once it is loaded as a SharePoint app part and put into a SharePoint page, the People picker control did not render.
进一步查看代码示例。一旦加载了样本,所有的javascript库都加载了,但是调试器抱怨无法找到全局函数SPClientPeoplePicker_InitStandaloneWrapper()。
Further looking at the code sample. Once the sample is loaded, all the javascript library loaded ok, but the debugger complained that global function SPClientPeoplePicker_InitStandaloneWrapper() cannot be found.
任何人都可以告诉我为什么缺少全局函数,尽管如此是否加载了clientpeoplepicker.js?
Can anyone tell me why the global function is missing, eventhough the clientpeoplepicker.js is loaded?
以下是新的ClientWebPart.aspx
Below is the new ClientWebPart.aspx
<%-- The following 4 lines are ASP.NET directives needed when using SharePoint components --%>
<%@ Page language="C#" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, 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" %>
<%@ 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" %>
<!-- The following tells SharePoint to allow this page to be hosted in an IFrame -->
<WebPartPages:AllowFraming runat="server" />
<html>
<head>
<!-- The following scripts are needed when using the SharePoint object model -->
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.debug.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.debug.js"></script>
<!-- Add your CSS styles to the following file -->
<link rel="Stylesheet" type="text/css" href="../Content/App.css" />
<!-- Add your JavaScript to the following file -->
<script type="text/javascript" src="../Scripts/App.js"></script>
<script type="text/javascript">
// Set the style of the client web part page to be consistent with the host web.
function setStyleSheet() {
var hostUrl = ""
if (document.URL.indexOf("?") != -1) {
var params = document.URL.split("?")[1].split("&");
for (var i = 0; i < params.length; i++) {
p = decodeURIComponent(params[i]);
if (/^SPHostUrl=/i.test(p)) {
hostUrl = p.split("=")[1];
document.write("<link rel=\"stylesheet\" href=\"" + hostUrl + "/_layouts/15/defaultcss.ashx\" />");
break;
}
}
}
if (hostUrl == "") {
document.write("<link rel=\"stylesheet\" href=\"/_layouts/15/1033/styles/themable/corev15.css\" />");
}
}
setStyleSheet();
</script>
<!-- The following script runs when the DOM is ready. The inline code uses a SharePoint feature to ensure -->
<!-- The SharePoint script file sp.js is loaded and will then execute the sharePointReady() function in App.js -->
<script type="text/javascript">
$(document).ready(function () {
//Get the URI decoded SharePoint site url from the SPHostUrl parameter.
var spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
//Build absolute path to the layouts root with the spHostUrl
var layoutsRoot = spHostUrl + '/_layouts/15/';
$.getScript(layoutsRoot + "SP.Runtime.js", function () {
$.getScript(layoutsRoot + "SP.js", function () {
$.getScript(layoutsRoot + "SP.Core.js", function () {
$.getScript(layoutsRoot + "clienttemplates.js", function () {
$.getScript(layoutsRoot + "clientforms.js", function () {
$.getScript(layoutsRoot + "clientpeoplepicker.js", function () {
$.getScript(layoutsRoot + "autofill.js", function () {
// Specify the unique ID of the DOM element where the
// picker will render.
initializePeoplePicker('peoplePickerDiv');
});
});
});
});
});
});
});
});
function getQueryStringParameter(urlParameterKey) {
var params = document.URL.split('?')[1].split('&');
var strParams = '';
for (var i = 0; i < params.length; i = i + 1) {
var singleParam = params[i].split('=');
if (singleParam[0] == urlParameterKey)
return decodeURIComponent(singleParam[1]);
}
}
</script>
</head>
<body class="partBody">
<div class="partDiv">
<span class="partContent">
<div id="peoplePickerDiv"></div>
<div>
<br/>
<input type="button" value="Get User Info" onclick="getUserInfo()"></input>
<br/>
<h1>User info:</h1>
<p id="resolvedUsers"></p>
<h1>User keys:</h1>
<p id="userKeys"></p>
</div>
</span>
</div>
</body>
</html>
以下是截图:
推荐答案
Clientwebpart.aspx不使用任何母版页。因此,某些SharePoint js文件未添加到页面中。这就是你得到错误的原因。
Clientwebpart.aspx doesn't use any master page. So some of the SharePoint js files are not added to the page. that's the reason you are getting the error.
问候,
Rajeswari
Rajeswari
这篇关于无法在SharePoint 2013应用程序部件中初始化人员选取器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!