我使用sharepoint服務3.0,我創建了自定義列表表單。我有這種形式的peoplepicker字段,並且需要將其默認設置爲當前用戶。設置peoplepicker默認值與當前用戶與JS
這是我到目前爲止有:
首先我peoplepicker fonction:
功能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」);
function SetWebUserData(){ var pplPicker = new PeoplePicker(); //設置選擇器的人員的父標籤ID。 pplPicker.SetParentTagId('ctl00_PlaceHolderMain_g_ec44fef5_c1a6_4ade_b7e4_2b80803724a1_ff6_1_ctl00_ctl00_UserField'); pplPicker.SetLoggedInUser(); }
但是當我我使用了錯誤的父標籤ID加載形式...沒有任何反應?我把它從頁面的源代碼...
任何幫助將是偉大的!
非常感謝!得到它的工作:) – MademoiselleLenore
什麼是DName?我是否需要用DName替換用戶名,我將如何自動執行此操作以獲取當前登錄的用戶? – Batman
在上述情況下,'Dname'是查詢字符串參數,即用戶名作爲QS參數傳遞。您可以使用SPServices獲取當前用戶。 – Ishan