Reputation: 4103
I'm following the book Getting Started With Meteor and I'm really not getting far because simple errors keep blocking me.
At this point in time I've started writing the initial app in the book in which we make a new global connection.
Lists = new Meteor.Collection("lists");
We then add some data to that collection.
lists.insert({Category:"DVDs", items: {Name:"Item Name",Owner:"me",LentTo:"Internet"}})
I can verify that the data is entered by checking in the console
lists.find({}).count(); //returns 2
lists.findOne({Category:"DVDs"}) //returns the DVD category
However when I try to display this content in the DOM nothing is displayed.
<div id="categories-container">
{{> categories}}
</div>
<template name="categories">
<div class="title"><h3>My Stuff</h3></div>
<div id="categories">
{{#each lists}}
<div class="category">
{{Category}}
</div>
{{/each}}
</div>
</template>
This displays only my Title. I get no errors in the browser console or the command line console. Not sure how to diagnose this.
Upvotes: 2
Views: 3232
Reputation: 2147
I am pretty sure the reason is because you have
Lists = new Meteor.Collection("lists");
But then you do:
lists.insert({Category:"DVDs", items: {Name:"Item Name",Owner:"me",LentTo:"Internet"}})
lists.find({}).count(); //returns 2
lists.findOne({Category:"DVDs"}) //returns the DVD category
But you should do
Lists.insert({Category:"DVDs", items: {Name:"Item Name",Owner:"me",LentTo:"Internet"}})
Lists.find({}).count(); //returns 2
Lists.findOne({Category:"DVDs"}) //returns the DVD category
Because it is case sensitive. Then in your Template helper do a Lists.find({}) and you should be good to go.
Upvotes: 4
Reputation: 4103
By going off the comments here and by reading a bit more, the reasoning why was because there was nothing telling meteor that the template was defined.
This was solved by the following code:
Template.categories.lists = function (){
return Lists.find({}, {sort: {Category: 1}});
}
This tells it to find all of the records in the Lists collection and sort them by Category.
Upvotes: 0
Reputation: 1437
To make your time with the book Discover Meteor easier: If you have software that will compare two directories, get the book from git in a parallel directory to what you are typing in. Then, when you have problems, go to that directory in the terminal and git checkout the chapter. Now, compare the two folders and you'll see your spelling errors.
Learning quickly evolving stuff on the internet is a hard process. A lot of the tutorials you find only work for a period of time.
But the meteor book is different. They keep the code up. I personally typed along, and found my errors were solved on a better read (and often less thinking I knew what I was doing). I've talked two twenty-somethings through it, and they also consistently made new and creative punctuation or spelling choices for quite a while. There are also
meteor add xxx
meteor remove xxx
commands that are easy to miss.
But please trust that source (assuming you just got it, and aren't working from some old pdf) and doubt yourself, just for this tutorial. :)
Upvotes: 0
Reputation: 71810
Did you define a template helper to display your content?
You may need:
Template.categories.lists = function() {
return Lists.find({});
};
Check out the documentation for specifics:
http://docs.meteor.com/#templates
For faceting on categories, you'll probably want to set a reactive session value.
Upvotes: 2