当前项未在新函数中定义(已延迟)

Currentitem undefined in new function ( Deffered)

本文关键字:定义 延迟 函数 新函数      更新时间:2023-09-26

我正在 SharePoint 中编辑项目显示模板。 出现以下问题:

ctx(clientcontext).currentitem 在自定义函数中变为未定义。我该如何解决这个问题。

下面是一个简短的代码片段:

 var p = getFollowers();
 console.log("")
 console.debug(ctx.CurrentItem);
 p.done(function(result) {
  console.debug(followers);
  console.debug(ctx);
 });

我看不到我在这里错过了什么

编辑 1:

                var results;
    function successCallback() {
        console.debug("test");
        var clientContext = new SP.ClientContext.get_current();
        var counts = 0;
        var test = results.getEnumerator();
        while (test.moveNext()) {
        var person = test.get_current();
            followers.push(person.get_displayName());
            counts++;
        }
        $("#followers").text('(' + counts + ')');   
        this.d.resolve(followers);
    }
    function failCallback() {
        this.d.reject("something bad happened");
    }
    function getFollowers()
    {
        var d = $.Deferred();
        var clientContext = new SP.ClientContext.get_current();
        var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
        // Get the people who are following the current user.
        peopleFollowingMe = peopleManager.getMyFollowers();
        clientContext.load(peopleFollowingMe);
        results = peopleFollowingMe;
        var o = {d: d, results:results};
        clientContext.executeQueryAsync(Function.createDelegate(o, successCallback), Function.createDelegate(o, failCallback));
        return d.promise();
    }

我不是sharepoint的专家。我想知道 ctx 变量是否可以由 p.done() 修改。

为什么不在调用 p.done() 之前存储 CurrentItem?

 var p = getFollowers();
 console.log("");
 var currentItem = ctx.CurrentItem;
 console.debug(currentItem);
 p.done(function(result) {
     /* console.debug(followers); */
     console.debug(currentItem);
 });

顺便一提。您在回调中读取的关注者变量是什么?