Update template var

I’m trying to update a reactive var in my template with a value returned from a method on the server. I can see that the server is returning a value but I cant set the var myvar1 in the code below. What am I doing wrong? Thanks for any help.

        Meteor.call('mymethod', arg1, function(err, ret) {
        // Also tried this and self
        Template.instance().myvar1.set(ret);

in what function/helper or so you are calling that?

In Template.mytpl.events

Template.mytpl.created = function() {

this.myvar1 = new ReactiveVar(false);

};

and if you do in that onCreated. (And BTW it is onCreated in current meteor version, not created)

self = this;

and in that callback

self.myvar1.set(ret);

? there was thread regarding similar scoping inside callbacks on these forums.
But I dont remember what was the solution, I would try this one first probably.

Thanks for your answer but I have tried that and also

self.Template.instance().myvar1.set(ret);

with no success.

Maybe this:

var instance = Template.instance();
Meteor.call('mymethod', arg1, function(err, ret) {
  instance.myvar1.set(ret);
});

I did not notice that events handler.

you can pass event AND template instance as argument for event handlers.

so

‘click’: function(event, instance) {
instance.myvar1.set(ret);
}

mby :smiley:

YES, thats the way to do it. Thanks a lot Steve and shock.
In other situations with callbacks it usually works to do self = this and then use self in callback but not this time and with reactive var. Nice and easy solution, thanks.