sharepoint 人员选择控件使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sharepoint 人员选择控件使用相关的知识,希望对你有一定的参考价值。

  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;
}

以上是关于sharepoint 人员选择控件使用的主要内容,如果未能解决你的问题,请参考以下文章

SharePoint 2010 用户控件保存属性

带有 AjaxToolkit 的 Accordion 控件的 Sharepoint WebPart

使用client对象模型读取SharePoint列表数据

Sharepoint:WebPart 和 silverlight 控件之间的通信

创建加载用户控件的 SharePoint 2013 Web 部件

在 Sharepoint 2013 中将用户控件添加到 Web 部件