javascript - Meteor : Changes in collections are not reflected in rendered HTML -


i have been trying doing simple publish/subscribe in meteor , cannot work expect reading sources available such meteor documentation.

i using macbook pro osx yosemite , running node.js v0.10.40, meteor v1.1.0.2 , chrome version 43.0.2357.132 (64-bit).

here experiencing 2 different examples:

first: simple todos tutorial.

simple-todos.html

<head>   <title>todo list</title> </head>  <body>   <div class="container">     <header>       <h1>todo list</h1>     </header>      <ul>       {{#each tasks}}         {{> task}}       {{/each}}     </ul>   </div> </body>  <template name="task">   <li>{{text}}</li> </template> 

simple-todos.js

tasks = new meteor.collection("tasks");  // simple-todos.js if (meteor.isclient) {   // code runs on client   template.body.helpers({     tasks: function(){       tasks.find({});     }   }); } 

problem description

the tutorial states when adding items tasks should reflected live in browser. not. have tried adding items tasks.insert({text: "todo server", createdat: new date()}) in js console in chrome , in meteor shell. have added items using meteor mongo , still no changes in rendered client view

the autopublish package installed , can insert , query tasks collection js console in browser, changes not reflected in rendered html.

second: simple publish/subscribe scenario

basic.html

<head>   <title>basic</title> </head>  <body>   <h1>welcome meteor!</h1>   <p>text gets pushed</p> </body> 

basic.js.

messagecoll = new mongo.collection("messages");  if(meteor.isserver){   meteor.publish("messages",function(){     messagecoll.find({});   }) }  if(meteor.isclient){   meteor.subscribe("messages", {     onready: function () { console.log("onready , items arrive", arguments); }, onerror: function () { console.log("onerror", arguments); }   }); } 

problem description

when autopublish package added project works intended. can insert new items js console in chrome , can query messagecoll collection , retrieve results well.

when autopublish package removed can insert items in messagecoll collection js console in chrome , verify have been added querying collection in meteor shell. when try query either using messagecoll.findone() or messagecoll.find().fetch() return value undefined.

all changes being done in structure of html-document gets pushed expected.

neither onready or onerror callback functions gets called, points toward issue related subscribe method.

i think both problems pretty straightforward solve (but frustrating when can't work out why - i've been there). basically, aren't returning functions code doesn't have result.

in template helper need add return this:

tasks: function(){   return tasks.find({}); } 

similarly, in publication need return this:

meteor.publish("messages",function(){   return messagecoll.find({}); }) 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -