最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Meteor Collections are not displaying - Stack Overflow

programmeradmin0浏览0评论

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 mand line console. Not sure how to diagnose this.

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 mand line console. Not sure how to diagnose this.

Share Improve this question edited Dec 14, 2013 at 19:15 BenMorel 36.7k52 gold badges206 silver badges337 bronze badges asked Sep 15, 2013 at 14:58 thatgibbyguythatgibbyguy 4,1433 gold badges25 silver badges39 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 4

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.

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./#templates

For faceting on categories, you'll probably want to set a reactive session value.

To make your time with the book Discover Meteor easier: If you have software that will pare 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, pare 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

mands 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. :)

By going off the ments 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.

发布评论

评论列表(0)

  1. 暂无评论