1,先引入 js
<SharePoint:ScriptLink Name="clienttemplates.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink Name="clientforms.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink Name="clientpeoplepicker.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink Name="autofill.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink Name="sp.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink Name="sp.runtime.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink Name="sp.core.js" runat="server" LoadAfterUI="true" Localizable="false" />
2,添加div标签
<div id="peoplePickerCCDiv"></div>
3,初始化 initializePeoplePicker(peoplePickerCCDiv)
function initializePeoplePicker(peoplePickerElementId) {
var schema = {}; schema[‘PrincipalAccountType‘] = ‘User,DL,SecGroup,SPGroup‘; schema[‘SearchPrincipalSource‘] = 15; schema[‘ResolvePrincipalSource‘] = 15; schema[‘AllowMultipleValues‘] = true; schema[‘MaximumEntitySuggestions‘] = 50; schema[‘Width‘] = ‘280px‘; schema[‘Height‘] = ‘55px‘;
this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema); }
4,获取用户信息
function getUserInfo() {
var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;
var users = peoplePicker.GetAllUserInfo();
var userInfo = ‘‘;
if (users.length > 0) {
for (var i = 0; i < users.length; i++) {
var user = users[i];
var aduser = user.Key;
if (aduser.indexOf("|") >= 0) {
userInfo += aduser.substring(aduser.indexOf("|") + 1) + ";";
}
else {
userInfo += aduser + ";";
}
}
}
return userInfo;
}