我将此单一方法添加到sharepoint web Part。 即使它在不同的存储库中的不同项目中工作,但它在当前站点中不起作用,任何想法可能出错?
代码如下所示:
<script src="/sites/XXXXXX/Scripts/jquery-1.10.2.min.js"></script>
<script src="http://sharepoint.crescent.com/helpdesk/support/jquery.SPServices-
2013.01.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
//Get the current user name
var user = $().SPServices.SPGetCurrentUser();
//Find the Specific People picker field "Requester" and set its value
$().SPServices.SPFindPeoplePicker({
peoplePickerDisplayName: "Requester",
valueToSet: user,
checkNames: true
});
});
</script>
答案 0 :(得分:0)
如果它在SharePoint 2013中,请使用以下代码通过当前用户设置人员选择器控件:
<script type="text/javascript" src="/_layouts/15/clientpeoplepicker.js"></script>
<script type="text/jscript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var currUser = $().SPServices.SPGetCurrentUser({ fieldName: "Title" });
console.log(currUser);
window.setTimeout(function() {
SetAndResolvePeoplePicker("testuser", currUser);
}, 750);
});
function SetAndResolvePeoplePicker(fieldName,Name)
{
var controlName = fieldName;
var peoplePickerDiv = $("[id$='ClientPeoplePicker'][title='" + controlName + "']");
var peoplePickerEditor = peoplePickerDiv.find("[title='" + controlName + "']");
var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerDiv[0].id];
peoplePickerEditor.val(Name);
spPeoplePicker.AddUnresolvedUserFromEditor(true);
}
</script>