【问题标题】:Understanding SP.clientContext.executeQueryAsync and the order that it pulls data了解 SP.clientContext.executeQueryAsync 及其提取数据的顺序
【发布时间】: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.loadclientContext.executeQueryAsync 被调用,然后 console.log(userProfileProperties); 就会显示第二次数据的顺序与上一个函数循环中的顺序不同。

因此,我想知道为什么数据与传递给函数的数据不同,因为 clientContext.loadclientContext.executeQueryAsync 似乎正在影响它。

非常感谢

【问题讨论】:

    标签: javascript asynchronous sharepoint


    【解决方案1】:

    第一个日志只输出一个 JavaScript 对象声明,直到您调用 clientContext.loadclientContext.executeQueryAsync 时才填充用户配置文件。

    查看下面的截图。

    one thread for your reference

    【讨论】:

    • 感谢 Lee_MSFT,我看到在调用 clientContext.loadclientContext.executeQueryAsync 之前没有用户数据被填充。我仍在努力确定拨打电话的顺序。想象一下,在我的(父)函数中,我有一个值为 'lee1@e.com,lee2@e.com,lee3@e.com' 的字符串。我将字符串转换为数组并通过数组循环调用 getUserProperties 函数。我认为clientContext.loadclientContext.executeQueryAsync 工作的顺序是字符串中电子邮件的顺序,因为它们是两个独立的函数,但顺序不匹配
    猜你喜欢
    • 2017-03-08
    • 2015-05-10
    • 1970-01-01
    • 2015-09-09
    • 2018-06-20
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多