Currentitem在新函数中未定义(已缓冲)

时间:2016-01-24 18:41:32

标签: javascript sharepoint display-templates

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

ctx(clientcontext).currentitem在自定义函数中变为未定义。我怎么能解决这个问题呢。

这是一个litle代码段:

 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();
    }

1 个答案:

答案 0 :(得分:0)

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

为什么在调用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);
 });
顺便说一下。您在回调中读取的追随者变量是什么?