Wim's answer is a good one - {{num(queue)}}
is an elegant solution.
The reason you can't use queueNum
is that when you do
queueNum = people[(people.length-1)].queueNo
the value of queueNum
is set to whatever the value of people[(people.length-1)].queueNo
is at the time of the statement. When the queue is altered, queueNum
doesn't get re-evaluated. This isn't a Ractive thing so much as a JavaScript thing.
Another way of saying it is
a = 1;
b = 2;
foo = a + b; // foo === 3
a = 3;
b = 4;
alert( foo ); // alerts '3' - foo is the same, even though a and b changed
This is actually the same reason that the alert('here')
was only triggering when the page loaded - rather than telling Ractive to trigger the alert when the value changed by wrapping it in a function, as in the second code block of Wim's answer, the code was executed immediately.