문제

사람들 피커가 완료되고 사용자를 찾을 때 JS 기능을 트리거하는 방법이 있습니까?Client Side Development Pattern을 사용하여 SharePoint 2013 앱을 개발하고 있습니다.

에 대한




































ko

// First we need to get the selected user from the person selected in the people picker
$(document).ready(function () {

// Specify the unique ID of the DOM element where the
// picker will render.
initializePeoplePicker('employeePickerSpan');});

// Render and initialize the client-side People Picker.
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['OnUserResolvedClientScript'] = 'MyPickerUserResolved';
schema['Width'] = '250px';

// 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.
this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);

}

function MyPickerUserResolved(topElementId,  MyPickerUserResolvedusers) {
// users is set to GetAllUserInfo()
// Get the people picker object from the page.
var employeePicker =    this.SPClientPeoplePicker.SPClientPeoplePickerDict.employeePickerSpan_TopSpan;

// Get information about all employees.
var employees = employeePicker.GetAllUserInfo();
var employeeInfo = '';
for (var i = 0; i < employees.length; i++) {
    var employee = employees[i];
    for (var employeeProperty in employee) {
        employeeInfo += employeeProperty + ':  ' + employee[employeeProperty] + '<br>';
    }
}
$('#employeelineManager').html(employeeInfo);
}
.

도움이 되었습니까?

해결책

On creation of the ClientPeoplePicker you can set the OnUserResolvedClientScript property to a function like:

function MyPickerUserResolved (topElementId, users) { 
    // users is set to GetAllUserInfo()
} 

다른 팁

You could use some jQuery to identify when the field on the page changes. The DIV for the people picker will have plain text for items not yet checked (i.e. if you typed a name, but didn't hit check names) and a span for each item that it has checked.

Here are some examples of how to monitor a DIV like that: https://stackoverflow.com/questions/4979738/fire-jquery-event-on-div-change

This function work on Internet Explorer for me:

function MyPickerUserResolved (topElementId, users) {                    
  //prevent users == null
  if(users.length != 0){
    var UserManager = users[0].Description;
    alert(UserManager); // show message contains on user position 1;
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top