i editing item display template in sharepoint. following problem occurs:
ctx(clientcontext).currentitem becomes undefined in custom function. how can solve this.
here litle code snippet:
var p = getfollowers(); console.log("") console.debug(ctx.currentitem); p.done(function(result) { console.debug(followers); console.debug(ctx); });
i don't see miss here
edit 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); // people following 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(); }
i not expert of sharepoint. wondering if ctx variable can modified p.done().
why don't store currentitem before calling p.done() ?
var p = getfollowers(); console.log(""); var currentitem = ctx.currentitem; console.debug(currentitem); p.done(function(result) { /* console.debug(followers); */ console.debug(currentitem); });
by way. followers variable reading in callback ?
Comments
Post a Comment