【发布时间】:2018-05-11 09:22:33
【问题描述】:
我有一个函数可以遍历以逗号分隔的电子邮件地址列表。 在循环中,我们将一些参数(包括电子邮件地址)传递给使用 SP.clientContext 的“getUserProperties”函数。
我已将函数中的代码剥离为:
getUserProperties = function (targetUser, userCount, parentCtrl) {
var deferred = $.Deferred();
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
var userProfileProperties;
var profilePropertyNames = ["PictureURL", "PreferredName", "SPS-JobTitle", "Department", "WorkPhone", "WorkEmail", "PersonalSpace"];
var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(
clientContext,
targetUser,
profilePropertyNames);
userProfileProperties = peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);
console.log(userProfileProperties);
console.log(userProfilePropertiesForUser);
clientContext.load(userProfilePropertiesForUser);
clientContext.executeQueryAsync(function (sender, args) {
console.log(userProfileProperties);
},function (sender, args) {
deferred.reject(null);
});
return deferred.promise();
}
我在理解发生了什么方面的问题是,第一个 console.log(userProfileProperties); 以与前一个循环函数相同的顺序显示请求到控制台日志的数据。
这与 console.log(userProfilePropertiesForUser); 调用相同。
然而,一旦 clientContext.load 和 clientContext.executeQueryAsync 被调用,然后 console.log(userProfileProperties); 就会显示第二次数据的顺序与上一个函数循环中的顺序不同。
因此,我想知道为什么数据与传递给函数的数据不同,因为 clientContext.load 和 clientContext.executeQueryAsync 似乎正在影响它。
非常感谢
【问题讨论】:
标签: javascript asynchronous sharepoint