我正在使用 sharepoint services 3.0,并且创建了一个自定义列表表单。我在这个表单中有一个 peoplepicker 字段,需要默认设置为当前用户。
这是我到目前为止所得到的:
首先我的peoplepicker函数:
函数 PeoplePicker(){
this.context = null; this.web = null; this.currentUser = null; this.parentTagId = null this.SetParentTagId = function(id){ this.parentTagId = id; } this.SetLoggedInUser = function(){ if(this.parentTagId != null){ this.getWebUserData(); } } this.getWebUserData = function(){ this.context = new SP.ClientContext.get_current(); this.web = this.context.get_web(); this.currentUser = this.web.get_currentUser(); this.currentUser.retrieve(); this.context.load(this.web); this.context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod)); } this.onSuccessMethod = function(){ this.setDefaultValue(this.currentUser.get_title()); } this.onFailureMethod = function(){ alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace()); } this.setDefaultValue = function(value){ var parentTag = document.getElementById(this.parentTagId); if (parentTag != null) { var peoplePickerTag = this.getTagFromIdentifierAndTitle(parentTag, 'div', 'UserField_upLevelDiv', 'People Picker'); if (peoplePickerTag) { peoplePickerTag.innerHTML = value; } } } this.getTagFromIdentifierAndTitle = function(parentElement, tagName, identifier, title){ var len = identifier.length; var tags = parentElement.getElementsByTagName(tagName); for (var i = 0; i < tags.length; i++) { var tempString = tags[i].id; if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) { return tags[i]; } } return null; }
}
其次,我在我的 asp 内容中使用它的方式:
ExecuteOrDelayUntilScriptLoaded(SetWebUserData, "PeoplePicker.js");
函数 SetWebUserData() { var pplPicker = new PeoplePicker(); // 设置选择器的人的父标签ID。pplPicker.SetParentTagId('ctl00_PlaceHolderMain_g_ec44fef5_c1a6_4ade_b7e4_2b80803724a1_ff6_1_ctl00_ctl00_UserField'); pplPicker.SetLoggedInUser(); }
但是当我加载表单时没有任何反应......我是否使用了错误的父标签 ID?我从页面的源代码中获取它...
任何帮助都会很棒!