我创建了一个from并在其中添加了一些文本框,并且我创建了一个工作正常的人员选择器,我甚至可以在我的字段中选择多个用户,但如果我在我的列表中选择了2个人只保存了1个人。因此,如果我在人员选择器中选择多个用户:
Audienca
列是一行文字
如何保存两个用户
我的人员选择器代码是:
My ascx
<SharePoint:ScriptLink ID="ScriptLink1" Name="clienttemplates.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink2" Name="clientforms.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink3" Name="clientpeoplepicker.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink4" Name="autofill.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink5" Name="sp.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink6" Name="sp.runtime.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink7" Name="sp.core.js" runat="server" LoadAfterUI="true" Localizable="false" />
<div id="audienceSelector" style="float: left;"></div>
<div class="clear"> </div>
<div class="clear"> </div>
<div class="clear"> </div>
<div class="clear"> </div>
C#代码
initializePeoplePicker('audienceSelector');//this is on top
function initializePeoplePicker(peoplePickerElementId) {
// Create a schema to store picker properties, and set the properties.
var schema = {};
schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
schema['SearchPrincipalSource'] = 15;
schema['ResolvePrincipalSource'] = 15;
schema['AllowMultipleValues'] = true;
schema['MaximumEntitySuggestions'] = 50;
schema['Width'] = '300px';
// Render and initialize the picker.
// Pass the ID of the DOM element that contains the picker, an array of initial
// PickerEntity objects to set the picker value, and a schema that defines
// picker properties.
SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
}
这是我尝试保存数据时的代码
var itemCreateInfo = new SP.ListItemCreationInformation();
var listItem = quizList.addItem(itemCreateInfo);
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict.audienceSelector_TopSpan;
// Get information about interviewer
var users = peoplePicker.GetAllUserInfo();
for (var i = 0; i < 1; i++) {
user = users[0];
interviewerName = user["DisplayText"];
}
listItem.set_item("Title", $('#newTestName').val());
//listItem.set_item("Audienca", $('#audienceSelector').val().toString());
listItem.set_item("Audienca", interviewerName);
答案 0 :(得分:1)
如果您将For循环中的users数组更改为使用[I]而不是[0],会发生什么:
for (var i = 0; i < 1; i++) {
user = users[i];
interviewerName = user["DisplayText"];
}
另外,我会使用一个人或组列,它会带来更多功能,如presence indicatiors。确保列表中的字段设置为允许多个选择 in the list settings.