Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The Meteor version of #each expects a <code>Cursor</code> or an <code>Array</code> as your codes points <code>items</code> as this is a child attribute of each document your function returns <code>undefined</code> so you'll need to loop over all Docs then items or findOne({_id:???}) loop of it's items;</p> <p>So the following works (favouring version 1) for returning all docs in the collection:</p> <ol> <li><code>return col.find()</code></li> <li><code>return col.find().fetch()</code></li> </ol> <p>Also you should only be declaring the collection once in a common script then pub/sub in the respective Working code below, post back if you have questions.</p> <p>.html</p> <pre><code> 1 &lt;head&gt; 2 &lt;title&gt;test&lt;/title&gt; 3 &lt;/head&gt; 4 5 &lt;body&gt; 6 {{&gt; hello}} 7 &lt;/body&gt; 8 9 &lt;template name="hello"&gt; 10 &lt;h1&gt;Where did the data gone to?&lt;/h1&gt; 11 Items from the test collection: 12 &lt;ul id="docs"&gt; 13 {{#each docs}} 14 &lt;li&gt;Doc: {{title}} 15 &lt;ul class="items"&gt; 16 {{#each items}} 17 &lt;li&gt;Item: {{title}}&lt;/li&gt; 18 {{/each}} 19 &lt;/ul&gt; 20 &lt;/li&gt; 21 {{/each}} 22 &lt;/ul&gt; 23 &lt;/template&gt; </code></pre> <p>.js</p> <pre><code> 1 // client 2 // 3 Col = new Meteor.Collection('testcol'); 4 // 5 // // I have tried wrapping this in autosubscribe as well: 6 if(Meteor.is_client){ 7 Meteor.subscribe('testcol'); 8 9 Template.hello.docs = function() { 10 return Col.find(); 11 } 12 } 13 14 15 // server 16 17 if (Meteor.is_server) { 18 19 Meteor.publish('testcol', function() { 20 return Col.find(); 21 }); 22 } 23 24 25 // bootstrap: 26 27 Meteor.startup(function () { 28 if (Col.find().count() &lt; 5) { 29 for (var i=0; i&lt;5; i++) { 30 Col.insert({ 31 title: 'Test ' + i, 32 items: [ 33 {title: 'item 1', value:true}, 34 {title: 'item 2', value:false}, 35 {title: 'item 3', value:true} 36 ] 37 }); 38 } 39 } 40 }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload