68926

Questions Meteor about changing view and putting array in collection

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); }

Recommend

  • How to determine if $addToSet actually added a new item into a MongoDB document or if the item alrea
  • Vue2 watch Set Not Working
  • Mongo collection query and Operators
  • Increase the speed of redrawing contour plot in matplotlib
  • ObjectID generated by server on pymongo
  • Mongodb $addToSet of nested object
  • Jquery javascript: have a filtering list(works), need help keeping all LI's visible when there&
  • How to hide the cursor in windows when dragging and dropping (possibly in python, or another languag
  • Plot a decision tree with R
  • javascript XSLT nodes, selecting the first of a group (merge-like)
  • Calling a second level base class constructor
  • Is it possible to utilize $addToSet multiple times in the same update?
  • How to record a JNLP/ Java Web Start application with JMeter
  • css font-size and line-height not matching the baseline
  • How to make nicEditor snaplet? (Several questions)
  • Certain Arabic text gets incorrectly shown while other Arabic text gets showed normally?
  • How to implement Deep Linking in Roku SG application?
  • Where these are stored?
  • abstracting over a collection
  • How can I tell a form not to dispose a particular control when it closes?
  • ActiveRecord query for a count of new users by day
  • Android full screen on only one activity?
  • Calling of Constructors in a Java
  • Unanticipated behavior
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • Cannot Parse HTML Data Using Android / JSOUP
  • retrieve vertices with no linked edge in arangodb
  • PHP: When would you need the self:: keyword?
  • How to delete a row from a dynamic generate table using jquery?
  • Acquiring multiple attributes from .xml file in c#
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • using HTMLImports.whenReady not working in chrome
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Getting Messege Twice Using IMvxMessenger
  • Authorize attributes not working in MVC 4
  • EntityFramework adding new object to nested object collection
  • reshape alternating columns in less time and using less memory
  • How can I use threading to 'tick' a timer to be accessed by other threads?
  • How to load view controller without button in storyboard?