68926

Question:
I got two question about the Meteor framework
First of all, how can I put an array inside a Meteor collection? And how can I push values into it?
Second of all, when I have a button and I click on it, how can I change the current view? Is this by hiding and showing templates?
Thanks!
Answer1:Use <a href="http://docs.mongodb.org/manual/reference/operator/addToSet/" rel="nofollow">$addToSet</a> to push values into an array:
var coll = new Meteor.Collection;
coll.insert({myArray: []});
coll.update({}, {$addToSet: {myArray: "myNewValue"}});
There are many ways to change views, but an easy one is to use Session
and check whether it has a value in your template:
<template name="mytemplate">
<button>Say hello</button>
{{#if sayHello}}Hello
{{/if}}
</template>
Template.mytemplate.events({
"click button": function() {
Session.set("sayHello", true);
}
});
Template.mytemplate.sayHello = function() {
return Session.equals("sayHello", true);
}