2

任何人都可以帮助我使用 javascript 从人员列中获取用户信息吗?到目前为止,我已经能够读取列表项并返回一个 SP.FieldUserValue,我可以从中获取一个数字 ID(不确定这个 ID 是什么)和显示名称。例如

var ManVal  = oListItem.get_item("RecruitingManager").get_lookupValue();
var ManId   = oListItem.get_item("RecruitingManager").get_lookupId();

如何更进一步创建 sp 用户对象?

最终,我想要实现的是从列表中检索详细信息,然后填充人员编辑器。

4

2 回答 2

3

好的,我明白了。

这是我的代码,希望对某人有所帮助。我没有包括检索列表项的方法,只是从该函数中获取该人的价值的行。

var _lineManager;

var lineManager = oListItem.get_item("RecruitingManager").get_lookupId();

_lineManager = oWebsite.getUserById(lineManager);

getLineManager();

function getLineManager() {
    context.load(_lineManager);
    context.executeQueryAsync(onGetUserNameSuccessLM, onGetUserNameFailLM);
}
function onGetUserNameSuccessLM() {
    alert(lineManager.get_title());

    var schema = {};
    schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
    schema['SearchPrincipalSource'] = 15;
    schema['ResolvePrincipalSource'] = 15;
    schema['AllowMultipleValues'] = false;
    schema['MaximumEntitySuggestions'] = 50;
    schema['Width'] = '280px';

    var users = new Array(1);
    var defaultUser = new Object();
    defaultUser.AutoFillDisplayText = lineManager.get_title();
    defaultUser.AutoFillKey = lineManager.get_loginName();
    defaultUser.Description = lineManager.get_email();
    defaultUser.DisplayText = lineManager.get_title();
    defaultUser.EntityType = "User";
    defaultUser.IsResolved = true;
    defaultUser.Key = lineManager.get_loginName();
    defaultUser.Resolved = true;
    users[0] = defaultUser;

    SPClientPeoplePicker_InitStandaloneControlWrapper('peoplePickerDivLinMan', users, schema);

}

function onGetUserNameFailLM(sender, args) {
    alert('Failed to get user name. Error:' + args.get_message());
}
于 2013-07-18T09:59:44.343 回答
0

person 字段(实际上称为“人员选择器”)有一个特定的 JavaScript 函数,您可能会发现它很有用:GetAllUserInfo()

MSDN 上有一篇不错的文章: How to: Use the client-side People Picker control in apps for SharePoint

相关代码为:

// Get the people picker object from the page.
var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;

// Get information about all users.
var users = peoplePicker.GetAllUserInfo();
var userInfo = '';
for (var i = 0; i < users.length; i++) {
    var user = users[i];
    for (var userProperty in user) { 
        userInfo += userProperty + ':  ' + user[userProperty] + '<br>';
    }
}
$('#resolvedUsers').html(userInfo);

// Get user keys.
var keys = peoplePicker.GetAllUserKeys();
$('#userKeys').html(keys);

所以基本上你必须将你的字段转换为 a SPClientPeoplePicker,然后可以GetAllUserInfo用来迭代该字段中的所有用户。

于 2013-07-17T08:19:55.377 回答