How to create dynamic ReactiveVar


#1

Hi,

var x = “something”;
Session.set(x, “anything”).

can you do the same with ReactiveVar?

this.x = new ReactiveVar(“anything”);

where x = “something”.

TIA!


#2

You’ll want to take care that this is actually what you expect it to be, but you can assign object properties values using bracket notation to achieve your desired outcome.

var x = “something”;

this[x] = new ReactiveVar(“anything”);

#3

Basically the ReactiveVar works just as the Session apart from that it is connected to a context, so it is always dynamic.

‘var’, ‘this’ and ‘Session’ is in your example just different context