使用javascript从sharepoint人员选取器检索电子邮件地址

使用javascript从sharepoint人员选取器检索电子邮件地址,sharepoint,peoplepicker,Sharepoint,Peoplepicker,我正在使用SharePoint 2007。我在layouts文件夹中有一个自定义aspx页面,其中包含一个people picker PeopleEditor控件 用户可以在控件中输入n个用户。我想使用javascript从people picker控件重新查看用户的电子邮件,请有人帮忙。General “人员”字段相当复杂,但我会尽我所能解释在更新我的库时使用这些字段所得到的结果。您可以查看库中的SPUserField类。我主要使用Firebug+Firefox对该领域进行反向工程。不幸的是,

我正在使用SharePoint 2007。我在layouts文件夹中有一个自定义aspx页面,其中包含一个people picker PeopleEditor控件

用户可以在控件中输入n个用户。我想使用javascript从people picker控件重新查看用户的电子邮件,请有人帮忙。

General “人员”字段相当复杂,但我会尽我所能解释在更新我的库时使用这些字段所得到的结果。您可以查看库中的SPUserField类。我主要使用Firebug+Firefox对该领域进行反向工程。不幸的是,根据所使用的浏览器,字段的生成方式有所不同

在Firefox中,会显示一个常规的旧文本区域。 在IE中,似乎使用了内容可编辑的div。 首先,组成字段的控件列表:

upLevelDiv-按下层文本框显示的内容可编辑div 下层文本框-文本区域 hiddenSpanData-存储某些数据的文本框 checkNames-ImageButton用户单击以通过AJAX验证输入的名称 实际上还有几个控件,但我还没有发现它们是有用的HiddenEntityKey、HiddenEntityDisplayText

获取控件 我不确定HTML在ASPX页面中是如何工作的,但在常规SharePoint表单中,有一个问题。所有其他控件似乎都包含在此范围内。这使得获得其他控件相对容易:

var controls = this.Controls.select('span.ms-usereditor');
if (null !== controls && 1 === controls.length) {
    this.spanUserField = controls[0];
    this.upLevelDiv = $(this.spanUserField.id + '_upLevelDiv');
    this.textareaDownLevelTextBox = $(this.spanUserField.id + '_downlevelTextBox');
    this.linkCheckNames = $(this.spanUserField.id + '_checkNames');
    this.txtHiddenSpanData = $(this.spanUserField.id + '_hiddenSpanData');
}
设置字段 为了理解,我还提供了设置字段的详细信息

if (Prototype.Browser.IE) {
    this.upLevelDiv.innerHTML = value;
    this.txtHiddenSpanData.setValue(value);
    this.linkCheckNames.click();
}
else { // FireFox (maybe others?)
    this.textareaDownLevelTextBox.setValue(value);
    this.linkCheckNames.onclick();
}
获取字段值 单击checknames按钮并执行AJAX之后,您的控件将填充新信息。upLevelDiv似乎包含了其中的大部分,但hiddenSpanData也包含了一些

执行后,upLevelDiv或hiddenSpanData可能包含以下内容:

<SPAN class=ms-entity-resolved id=spanDOMAIN\account12345 title=DOMAIN\account12345 contentEditable=false tabIndex=-1>
<DIV id=divEntityData style="DISPLAY: none" description="DOMAIN\account12345" isresolved="True" displaytext="LastName, FirstName" key="DOMAIN\account12345">
<DIV data='<ArrayOfDictionaryEntry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><DictionaryEntry><Key xsi:type="xsd:string">SPUserID</Key><Value xsi:type="xsd:string">2</Value></DictionaryEntry><DictionaryEntry><Key xsi:type="xsd:string">Email</Key><Value xsi:type="xsd:string">email@address.com</Value></DictionaryEntry><DictionaryEntry><Key xsi:type="xsd:string">DisplayName</Key><Value xsi:type="xsd:string">LastName, FirstName</Value></DictionaryEntry><DictionaryEntry><Key xsi:type="xsd:string">Department</Key><Value xsi:type="xsd:string">My Department Name</Value></DictionaryEntry><DictionaryEntry><Key xsi:type="xsd:string">SIPAddress</Key><Value xsi:type="xsd:string">sip@address.com</Value></DictionaryEntry><DictionaryEntry><Key xsi:type="xsd:string">PrincipalType</Key><Value xsi:type="xsd:string">User</Value></DictionaryEntry><DictionaryEntry><Key xsi:type="xsd:string">Title</Key><Value xsi:type="xsd:string">My Job Title</Value></DictionaryEntry></ArrayOfDictionaryEntry>'></DIV></DIV><SPAN oncontextmenu=onContextMenuSpnRw(); onmousedown=onMouseDownRw(); id=content contentEditable=true tabIndex=-1>LastName, FirstName</SPAN></SPAN>
然后,您所需要做的就是解析ArrayOfDictionaryEntry XML对象来读取他们的电子邮件