0

我正在 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();
    }
4

1 回答 1

0

我不是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);
 });

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

于 2016-01-24T18:51:45.727 回答